<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.22">
<title>fok-js使用手册</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<style>
/*! Asciidoctor default stylesheet | MIT License | https://asciidoctor.org */
/* Uncomment the following line when using as a custom stylesheet */
/* @import "https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700"; */
html{font-family:sans-serif;-webkit-text-size-adjust:100%}
a{background:none}
a:focus{outline:thin dotted}
a:active,a:hover{outline:0}
h1{font-size:2em;margin:.67em 0}
b,strong{font-weight:bold}
abbr{font-size:.9em}
abbr[title]{cursor:help;border-bottom:1px dotted #dddddf;text-decoration:none}
dfn{font-style:italic}
hr{height:0}
mark{background:#ff0;color:#000}
code,kbd,pre,samp{font-family:monospace;font-size:1em}
pre{white-space:pre-wrap}
q{quotes:"\201C" "\201D" "\2018" "\2019"}
small{font-size:80%}
sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}
sup{top:-.5em}
sub{bottom:-.25em}
img{border:0}
svg:not(:root){overflow:hidden}
figure{margin:0}
audio,video{display:inline-block}
audio:not([controls]){display:none;height:0}
fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}
legend{border:0;padding:0}
button,input,select,textarea{font-family:inherit;font-size:100%;margin:0}
button,input{line-height:normal}
button,select{text-transform:none}
button,html input[type=button],input[type=reset],input[type=submit]{-webkit-appearance:button;cursor:pointer}
button[disabled],html input[disabled]{cursor:default}
input[type=checkbox],input[type=radio]{padding:0}
button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}
textarea{overflow:auto;vertical-align:top}
table{border-collapse:collapse;border-spacing:0}
*,::before,::after{box-sizing:border-box}
html,body{font-size:100%}
body{background:#fff;color:rgba(0,0,0,.8);padding:0;margin:0;font-family:"Noto Serif","DejaVu Serif",serif;line-height:1;position:relative;cursor:auto;-moz-tab-size:4;-o-tab-size:4;tab-size:4;word-wrap:anywhere;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}
a:hover{cursor:pointer}
img,object,embed{max-width:100%;height:auto}
object,embed{height:100%}
img{-ms-interpolation-mode:bicubic}
.left{float:left!important}
.right{float:right!important}
.text-left{text-align:left!important}
.text-right{text-align:right!important}
.text-center{text-align:center!important}
.text-justify{text-align:justify!important}
.hide{display:none}
img,object,svg{display:inline-block;vertical-align:middle}
textarea{height:auto;min-height:50px}
select{width:100%}
.subheader,.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{line-height:1.45;color:#7a2518;font-weight:400;margin-top:0;margin-bottom:.25em}
div,dl,dt,dd,ul,ol,li,h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6,pre,form,p,blockquote,th,td{margin:0;padding:0}
a{color:#2156a5;text-decoration:underline;line-height:inherit}
a:hover,a:focus{color:#1d4b8f}
a img{border:0}
p{line-height:1.6;margin-bottom:1.25em;text-rendering:optimizeLegibility}
p aside{font-size:.875em;line-height:1.35;font-style:italic}
h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{font-family:"Open Sans","DejaVu Sans",sans-serif;font-weight:300;font-style:normal;color:#ba3925;text-rendering:optimizeLegibility;margin-top:1em;margin-bottom:.5em;line-height:1.0125em}
h1 small,h2 small,h3 small,#toctitle small,.sidebarblock>.content>.title small,h4 small,h5 small,h6 small{font-size:60%;color:#e99b8f;line-height:0}
h1{font-size:2.125em}
h2{font-size:1.6875em}
h3,#toctitle,.sidebarblock>.content>.title{font-size:1.375em}
h4,h5{font-size:1.125em}
h6{font-size:1em}
hr{border:solid #dddddf;border-width:1px 0 0;clear:both;margin:1.25em 0 1.1875em}
em,i{font-style:italic;line-height:inherit}
strong,b{font-weight:bold;line-height:inherit}
small{font-size:60%;line-height:inherit}
code{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;color:rgba(0,0,0,.9)}
ul,ol,dl{line-height:1.6;margin-bottom:1.25em;list-style-position:outside;font-family:inherit}
ul,ol{margin-left:1.5em}
ul li ul,ul li ol{margin-left:1.25em;margin-bottom:0}
ul.circle{list-style-type:circle}
ul.disc{list-style-type:disc}
ul.square{list-style-type:square}
ul.circle ul:not([class]),ul.disc ul:not([class]),ul.square ul:not([class]){list-style:inherit}
ol li ul,ol li ol{margin-left:1.25em;margin-bottom:0}
dl dt{margin-bottom:.3125em;font-weight:bold}
dl dd{margin-bottom:1.25em}
blockquote{margin:0 0 1.25em;padding:.5625em 1.25em 0 1.1875em;border-left:1px solid #ddd}
blockquote,blockquote p{line-height:1.6;color:rgba(0,0,0,.85)}
@media screen and (min-width:768px){h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2}
h1{font-size:2.75em}
h2{font-size:2.3125em}
h3,#toctitle,.sidebarblock>.content>.title{font-size:1.6875em}
h4{font-size:1.4375em}}
table{background:#fff;margin-bottom:1.25em;border:1px solid #dedede;word-wrap:normal}
table thead,table tfoot{background:#f7f8f7}
table thead tr th,table thead tr td,table tfoot tr th,table tfoot tr td{padding:.5em .625em .625em;font-size:inherit;color:rgba(0,0,0,.8);text-align:left}
table tr th,table tr td{padding:.5625em .625em;font-size:inherit;color:rgba(0,0,0,.8)}
table tr.even,table tr.alt{background:#f8f8f7}
table thead tr th,table tfoot tr th,table tbody tr td,table tr td,table tfoot tr td{line-height:1.6}
h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2;word-spacing:-.05em}
h1 strong,h2 strong,h3 strong,#toctitle strong,.sidebarblock>.content>.title strong,h4 strong,h5 strong,h6 strong{font-weight:400}
.center{margin-left:auto;margin-right:auto}
.stretch{width:100%}
.clearfix::before,.clearfix::after,.float-group::before,.float-group::after{content:" ";display:table}
.clearfix::after,.float-group::after{clear:both}
:not(pre).nobreak{word-wrap:normal}
:not(pre).nowrap{white-space:nowrap}
:not(pre).pre-wrap{white-space:pre-wrap}
:not(pre):not([class^=L])>code{font-size:.9375em;font-style:normal!important;letter-spacing:0;padding:.1em .5ex;word-spacing:-.15em;background:#f7f7f8;border-radius:4px;line-height:1.45;text-rendering:optimizeSpeed}
pre{color:rgba(0,0,0,.9);font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;line-height:1.45;text-rendering:optimizeSpeed}
pre code,pre pre{color:inherit;font-size:inherit;line-height:inherit}
pre>code{display:block}
pre.nowrap,pre.nowrap pre{white-space:pre;word-wrap:normal}
em em{font-style:normal}
strong strong{font-weight:400}
.keyseq{color:rgba(51,51,51,.8)}
kbd{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;display:inline-block;color:rgba(0,0,0,.8);font-size:.65em;line-height:1.45;background:#f7f7f7;border:1px solid #ccc;border-radius:3px;box-shadow:0 1px 0 rgba(0,0,0,.2),inset 0 0 0 .1em #fff;margin:0 .15em;padding:.2em .5em;vertical-align:middle;position:relative;top:-.1em;white-space:nowrap}
.keyseq kbd:first-child{margin-left:0}
.keyseq kbd:last-child{margin-right:0}
.menuseq,.menuref{color:#000}
.menuseq b:not(.caret),.menuref{font-weight:inherit}
.menuseq{word-spacing:-.02em}
.menuseq b.caret{font-size:1.25em;line-height:.8}
.menuseq i.caret{font-weight:bold;text-align:center;width:.45em}
b.button::before,b.button::after{position:relative;top:-1px;font-weight:400}
b.button::before{content:"[";padding:0 3px 0 2px}
b.button::after{content:"]";padding:0 2px 0 3px}
p a>code:hover{color:rgba(0,0,0,.9)}
#header,#content,#footnotes,#footer{width:100%;margin:0 auto;max-width:62.5em;*zoom:1;position:relative;padding-left:.9375em;padding-right:.9375em}
#header::before,#header::after,#content::before,#content::after,#footnotes::before,#footnotes::after,#footer::before,#footer::after{content:" ";display:table}
#header::after,#content::after,#footnotes::after,#footer::after{clear:both}
#content{margin-top:1.25em}
#content::before{content:none}
#header>h1:first-child{color:rgba(0,0,0,.85);margin-top:2.25rem;margin-bottom:0}
#header>h1:first-child+#toc{margin-top:8px;border-top:1px solid #dddddf}
#header>h1:only-child{border-bottom:1px solid #dddddf;padding-bottom:8px}
#header .details{border-bottom:1px solid #dddddf;line-height:1.45;padding-top:.25em;padding-bottom:.25em;padding-left:.25em;color:rgba(0,0,0,.6);display:flex;flex-flow:row wrap}
#header .details span:first-child{margin-left:-.125em}
#header .details span.email a{color:rgba(0,0,0,.85)}
#header .details br{display:none}
#header .details br+span::before{content:"\00a0\2013\00a0"}
#header .details br+span.author::before{content:"\00a0\22c5\00a0";color:rgba(0,0,0,.85)}
#header .details br+span#revremark::before{content:"\00a0|\00a0"}
#header #revnumber{text-transform:capitalize}
#header #revnumber::after{content:"\00a0"}
#content>h1:first-child:not([class]){color:rgba(0,0,0,.85);border-bottom:1px solid #dddddf;padding-bottom:8px;margin-top:0;padding-top:1rem;margin-bottom:1.25rem}
#toc{border-bottom:1px solid #e7e7e9;padding-bottom:.5em}
#toc>ul{margin-left:.125em}
#toc ul.sectlevel0>li>a{font-style:italic}
#toc ul.sectlevel0 ul.sectlevel1{margin:.5em 0}
#toc ul{font-family:"Open Sans","DejaVu Sans",sans-serif;list-style-type:none}
#toc li{line-height:1.3334;margin-top:.3334em}
#toc a{text-decoration:none}
#toc a:active{text-decoration:underline}
#toctitle{color:#7a2518;font-size:1.2em}
@media screen and (min-width:768px){#toctitle{font-size:1.375em}
body.toc2{padding-left:15em;padding-right:0}
body.toc2 #header>h1:nth-last-child(2){border-bottom:1px solid #dddddf;padding-bottom:8px}
#toc.toc2{margin-top:0!important;background:#f8f8f7;position:fixed;width:15em;left:0;top:0;border-right:1px solid #e7e7e9;border-top-width:0!important;border-bottom-width:0!important;z-index:1000;padding:1.25em 1em;height:100%;overflow:auto}
#toc.toc2 #toctitle{margin-top:0;margin-bottom:.8rem;font-size:1.2em}
#toc.toc2>ul{font-size:.9em;margin-bottom:0}
#toc.toc2 ul ul{margin-left:0;padding-left:1em}
#toc.toc2 ul.sectlevel0 ul.sectlevel1{padding-left:0;margin-top:.5em;margin-bottom:.5em}
body.toc2.toc-right{padding-left:0;padding-right:15em}
body.toc2.toc-right #toc.toc2{border-right-width:0;border-left:1px solid #e7e7e9;left:auto;right:0}}
@media screen and (min-width:1280px){body.toc2{padding-left:20em;padding-right:0}
#toc.toc2{width:20em}
#toc.toc2 #toctitle{font-size:1.375em}
#toc.toc2>ul{font-size:.95em}
#toc.toc2 ul ul{padding-left:1.25em}
body.toc2.toc-right{padding-left:0;padding-right:20em}}
#content #toc{border:1px solid #e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;border-radius:4px}
#content #toc>:first-child{margin-top:0}
#content #toc>:last-child{margin-bottom:0}
#footer{max-width:none;background:rgba(0,0,0,.8);padding:1.25em}
#footer-text{color:hsla(0,0%,100%,.8);line-height:1.44}
#content{margin-bottom:.625em}
.sect1{padding-bottom:.625em}
@media screen and (min-width:768px){#content{margin-bottom:1.25em}
.sect1{padding-bottom:1.25em}}
.sect1:last-child{padding-bottom:0}
.sect1+.sect1{border-top:1px solid #e7e7e9}
#content h1>a.anchor,h2>a.anchor,h3>a.anchor,#toctitle>a.anchor,.sidebarblock>.content>.title>a.anchor,h4>a.anchor,h5>a.anchor,h6>a.anchor{position:absolute;z-index:1001;width:1.5ex;margin-left:-1.5ex;display:block;text-decoration:none!important;visibility:hidden;text-align:center;font-weight:400}
#content h1>a.anchor::before,h2>a.anchor::before,h3>a.anchor::before,#toctitle>a.anchor::before,.sidebarblock>.content>.title>a.anchor::before,h4>a.anchor::before,h5>a.anchor::before,h6>a.anchor::before{content:"\00A7";font-size:.85em;display:block;padding-top:.1em}
#content h1:hover>a.anchor,#content h1>a.anchor:hover,h2:hover>a.anchor,h2>a.anchor:hover,h3:hover>a.anchor,#toctitle:hover>a.anchor,.sidebarblock>.content>.title:hover>a.anchor,h3>a.anchor:hover,#toctitle>a.anchor:hover,.sidebarblock>.content>.title>a.anchor:hover,h4:hover>a.anchor,h4>a.anchor:hover,h5:hover>a.anchor,h5>a.anchor:hover,h6:hover>a.anchor,h6>a.anchor:hover{visibility:visible}
#content h1>a.link,h2>a.link,h3>a.link,#toctitle>a.link,.sidebarblock>.content>.title>a.link,h4>a.link,h5>a.link,h6>a.link{color:#ba3925;text-decoration:none}
#content h1>a.link:hover,h2>a.link:hover,h3>a.link:hover,#toctitle>a.link:hover,.sidebarblock>.content>.title>a.link:hover,h4>a.link:hover,h5>a.link:hover,h6>a.link:hover{color:#a53221}
details,.audioblock,.imageblock,.literalblock,.listingblock,.stemblock,.videoblock{margin-bottom:1.25em}
details{margin-left:1.25rem}
details>summary{cursor:pointer;display:block;position:relative;line-height:1.6;margin-bottom:.625rem;outline:none;-webkit-tap-highlight-color:transparent}
details>summary::-webkit-details-marker{display:none}
details>summary::before{content:"";border:solid transparent;border-left:solid;border-width:.3em 0 .3em .5em;position:absolute;top:.5em;left:-1.25rem;transform:translateX(15%)}
details[open]>summary::before{border:solid transparent;border-top:solid;border-width:.5em .3em 0;transform:translateY(15%)}
details>summary::after{content:"";width:1.25rem;height:1em;position:absolute;top:.3em;left:-1.25rem}
.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{text-rendering:optimizeLegibility;text-align:left;font-family:"Noto Serif","DejaVu Serif",serif;font-size:1rem;font-style:italic}
table.tableblock.fit-content>caption.title{white-space:nowrap;width:0}
.paragraph.lead>p,#preamble>.sectionbody>[class=paragraph]:first-of-type p{font-size:1.21875em;line-height:1.6;color:rgba(0,0,0,.85)}
.admonitionblock>table{border-collapse:separate;border:0;background:none;width:100%}
.admonitionblock>table td.icon{text-align:center;width:80px}
.admonitionblock>table td.icon img{max-width:none}
.admonitionblock>table td.icon .title{font-weight:bold;font-family:"Open Sans","DejaVu Sans",sans-serif;text-transform:uppercase}
.admonitionblock>table td.content{padding-left:1.125em;padding-right:1.25em;border-left:1px solid #dddddf;color:rgba(0,0,0,.6);word-wrap:anywhere}
.admonitionblock>table td.content>:last-child>:last-child{margin-bottom:0}
.exampleblock>.content{border:1px solid #e6e6e6;margin-bottom:1.25em;padding:1.25em;background:#fff;border-radius:4px}
.sidebarblock{border:1px solid #dbdbd6;margin-bottom:1.25em;padding:1.25em;background:#f3f3f2;border-radius:4px}
.sidebarblock>.content>.title{color:#7a2518;margin-top:0;text-align:center}
.exampleblock>.content>:first-child,.sidebarblock>.content>:first-child{margin-top:0}
.exampleblock>.content>:last-child,.exampleblock>.content>:last-child>:last-child,.exampleblock>.content .olist>ol>li:last-child>:last-child,.exampleblock>.content .ulist>ul>li:last-child>:last-child,.exampleblock>.content .qlist>ol>li:last-child>:last-child,.sidebarblock>.content>:last-child,.sidebarblock>.content>:last-child>:last-child,.sidebarblock>.content .olist>ol>li:last-child>:last-child,.sidebarblock>.content .ulist>ul>li:last-child>:last-child,.sidebarblock>.content .qlist>ol>li:last-child>:last-child{margin-bottom:0}
.literalblock pre,.listingblock>.content>pre{border-radius:4px;overflow-x:auto;padding:1em;font-size:.8125em}
@media screen and (min-width:768px){.literalblock pre,.listingblock>.content>pre{font-size:.90625em}}
@media screen and (min-width:1280px){.literalblock pre,.listingblock>.content>pre{font-size:1em}}
.literalblock pre,.listingblock>.content>pre:not(.highlight),.listingblock>.content>pre[class=highlight],.listingblock>.content>pre[class^="highlight "]{background:#f7f7f8}
.literalblock.output pre{color:#f7f7f8;background:rgba(0,0,0,.9)}
.listingblock>.content{position:relative}
.listingblock code[data-lang]::before{display:none;content:attr(data-lang);position:absolute;font-size:.75em;top:.425rem;right:.5rem;line-height:1;text-transform:uppercase;color:inherit;opacity:.5}
.listingblock:hover code[data-lang]::before{display:block}
.listingblock.terminal pre .command::before{content:attr(data-prompt);padding-right:.5em;color:inherit;opacity:.5}
.listingblock.terminal pre .command:not([data-prompt])::before{content:"$"}
.listingblock pre.highlightjs{padding:0}
.listingblock pre.highlightjs>code{padding:1em;border-radius:4px}
.listingblock pre.prettyprint{border-width:0}
.prettyprint{background:#f7f7f8}
pre.prettyprint .linenums{line-height:1.45;margin-left:2em}
pre.prettyprint li{background:none;list-style-type:inherit;padding-left:0}
pre.prettyprint li code[data-lang]::before{opacity:1}
pre.prettyprint li:not(:first-child) code[data-lang]::before{display:none}
table.linenotable{border-collapse:separate;border:0;margin-bottom:0;background:none}
table.linenotable td[class]{color:inherit;vertical-align:top;padding:0;line-height:inherit;white-space:normal}
table.linenotable td.code{padding-left:.75em}
table.linenotable td.linenos,pre.pygments .linenos{border-right:1px solid;opacity:.35;padding-right:.5em;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}
pre.pygments span.linenos{display:inline-block;margin-right:.75em}
.quoteblock{margin:0 1em 1.25em 1.5em;display:table}
.quoteblock:not(.excerpt)>.title{margin-left:-1.5em;margin-bottom:.75em}
.quoteblock blockquote,.quoteblock p{color:rgba(0,0,0,.85);font-size:1.15rem;line-height:1.75;word-spacing:.1em;letter-spacing:0;font-style:italic;text-align:justify}
.quoteblock blockquote{margin:0;padding:0;border:0}
.quoteblock blockquote::before{content:"\201c";float:left;font-size:2.75em;font-weight:bold;line-height:.6em;margin-left:-.6em;color:#7a2518;text-shadow:0 1px 2px rgba(0,0,0,.1)}
.quoteblock blockquote>.paragraph:last-child p{margin-bottom:0}
.quoteblock .attribution{margin-top:.75em;margin-right:.5ex;text-align:right}
.verseblock{margin:0 1em 1.25em}
.verseblock pre{font-family:"Open Sans","DejaVu Sans",sans-serif;font-size:1.15rem;color:rgba(0,0,0,.85);font-weight:300;text-rendering:optimizeLegibility}
.verseblock pre strong{font-weight:400}
.verseblock .attribution{margin-top:1.25rem;margin-left:.5ex}
.quoteblock .attribution,.verseblock .attribution{font-size:.9375em;line-height:1.45;font-style:italic}
.quoteblock .attribution br,.verseblock .attribution br{display:none}
.quoteblock .attribution cite,.verseblock .attribution cite{display:block;letter-spacing:-.025em;color:rgba(0,0,0,.6)}
.quoteblock.abstract blockquote::before,.quoteblock.excerpt blockquote::before,.quoteblock .quoteblock blockquote::before{display:none}
.quoteblock.abstract blockquote,.quoteblock.abstract p,.quoteblock.excerpt blockquote,.quoteblock.excerpt p,.quoteblock .quoteblock blockquote,.quoteblock .quoteblock p{line-height:1.6;word-spacing:0}
.quoteblock.abstract{margin:0 1em 1.25em;display:block}
.quoteblock.abstract>.title{margin:0 0 .375em;font-size:1.15em;text-align:center}
.quoteblock.excerpt>blockquote,.quoteblock .quoteblock{padding:0 0 .25em 1em;border-left:.25em solid #dddddf}
.quoteblock.excerpt,.quoteblock .quoteblock{margin-left:0}
.quoteblock.excerpt blockquote,.quoteblock.excerpt p,.quoteblock .quoteblock blockquote,.quoteblock .quoteblock p{color:inherit;font-size:1.0625rem}
.quoteblock.excerpt .attribution,.quoteblock .quoteblock .attribution{color:inherit;font-size:.85rem;text-align:left;margin-right:0}
p.tableblock:last-child{margin-bottom:0}
td.tableblock>.content{margin-bottom:1.25em;word-wrap:anywhere}
td.tableblock>.content>:last-child{margin-bottom:-1.25em}
table.tableblock,th.tableblock,td.tableblock{border:0 solid #dedede}
table.grid-all>*>tr>*{border-width:1px}
table.grid-cols>*>tr>*{border-width:0 1px}
table.grid-rows>*>tr>*{border-width:1px 0}
table.frame-all{border-width:1px}
table.frame-ends{border-width:1px 0}
table.frame-sides{border-width:0 1px}
table.frame-none>colgroup+*>:first-child>*,table.frame-sides>colgroup+*>:first-child>*{border-top-width:0}
table.frame-none>:last-child>:last-child>*,table.frame-sides>:last-child>:last-child>*{border-bottom-width:0}
table.frame-none>*>tr>:first-child,table.frame-ends>*>tr>:first-child{border-left-width:0}
table.frame-none>*>tr>:last-child,table.frame-ends>*>tr>:last-child{border-right-width:0}
table.stripes-all>*>tr,table.stripes-odd>*>tr:nth-of-type(odd),table.stripes-even>*>tr:nth-of-type(even),table.stripes-hover>*>tr:hover{background:#f8f8f7}
th.halign-left,td.halign-left{text-align:left}
th.halign-right,td.halign-right{text-align:right}
th.halign-center,td.halign-center{text-align:center}
th.valign-top,td.valign-top{vertical-align:top}
th.valign-bottom,td.valign-bottom{vertical-align:bottom}
th.valign-middle,td.valign-middle{vertical-align:middle}
table thead th,table tfoot th{font-weight:bold}
tbody tr th{background:#f7f8f7}
tbody tr th,tbody tr th p,tfoot tr th,tfoot tr th p{color:rgba(0,0,0,.8);font-weight:bold}
p.tableblock>code:only-child{background:none;padding:0}
p.tableblock{font-size:1em}
ol{margin-left:1.75em}
ul li ol{margin-left:1.5em}
dl dd{margin-left:1.125em}
dl dd:last-child,dl dd:last-child>:last-child{margin-bottom:0}
li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em}
ul.checklist,ul.none,ol.none,ul.no-bullet,ol.no-bullet,ol.unnumbered,ul.unstyled,ol.unstyled{list-style-type:none}
ul.no-bullet,ol.no-bullet,ol.unnumbered{margin-left:.625em}
ul.unstyled,ol.unstyled{margin-left:0}
li>p:empty:only-child::before{content:"";display:inline-block}
ul.checklist>li>p:first-child{margin-left:-1em}
ul.checklist>li>p:first-child>.fa-square-o:first-child,ul.checklist>li>p:first-child>.fa-check-square-o:first-child{width:1.25em;font-size:.8em;position:relative;bottom:.125em}
ul.checklist>li>p:first-child>input[type=checkbox]:first-child{margin-right:.25em}
ul.inline{display:flex;flex-flow:row wrap;list-style:none;margin:0 0 .625em -1.25em}
ul.inline>li{margin-left:1.25em}
.unstyled dl dt{font-weight:400;font-style:normal}
ol.arabic{list-style-type:decimal}
ol.decimal{list-style-type:decimal-leading-zero}
ol.loweralpha{list-style-type:lower-alpha}
ol.upperalpha{list-style-type:upper-alpha}
ol.lowerroman{list-style-type:lower-roman}
ol.upperroman{list-style-type:upper-roman}
ol.lowergreek{list-style-type:lower-greek}
.hdlist>table,.colist>table{border:0;background:none}
.hdlist>table>tbody>tr,.colist>table>tbody>tr{background:none}
td.hdlist1,td.hdlist2{vertical-align:top;padding:0 .625em}
td.hdlist1{font-weight:bold;padding-bottom:1.25em}
td.hdlist2{word-wrap:anywhere}
.literalblock+.colist,.listingblock+.colist{margin-top:-.5em}
.colist td:not([class]):first-child{padding:.4em .75em 0;line-height:1;vertical-align:top}
.colist td:not([class]):first-child img{max-width:none}
.colist td:not([class]):last-child{padding:.25em 0}
.thumb,.th{line-height:0;display:inline-block;border:4px solid #fff;box-shadow:0 0 0 1px #ddd}
.imageblock.left{margin:.25em .625em 1.25em 0}
.imageblock.right{margin:.25em 0 1.25em .625em}
.imageblock>.title{margin-bottom:0}
.imageblock.thumb,.imageblock.th{border-width:6px}
.imageblock.thumb>.title,.imageblock.th>.title{padding:0 .125em}
.image.left,.image.right{margin-top:.25em;margin-bottom:.25em;display:inline-block;line-height:0}
.image.left{margin-right:.625em}
.image.right{margin-left:.625em}
a.image{text-decoration:none;display:inline-block}
a.image object{pointer-events:none}
sup.footnote,sup.footnoteref{font-size:.875em;position:static;vertical-align:super}
sup.footnote a,sup.footnoteref a{text-decoration:none}
sup.footnote a:active,sup.footnoteref a:active,#footnotes .footnote a:first-of-type:active{text-decoration:underline}
#footnotes{padding-top:.75em;padding-bottom:.75em;margin-bottom:.625em}
#footnotes hr{width:20%;min-width:6.25em;margin:-.25em 0 .75em;border-width:1px 0 0}
#footnotes .footnote{padding:0 .375em 0 .225em;line-height:1.3334;font-size:.875em;margin-left:1.2em;margin-bottom:.2em}
#footnotes .footnote a:first-of-type{font-weight:bold;text-decoration:none;margin-left:-1.05em}
#footnotes .footnote:last-of-type{margin-bottom:0}
#content #footnotes{margin-top:-.625em;margin-bottom:0;padding:.75em 0}
div.unbreakable{page-break-inside:avoid}
.big{font-size:larger}
.small{font-size:smaller}
.underline{text-decoration:underline}
.overline{text-decoration:overline}
.line-through{text-decoration:line-through}
.aqua{color:#00bfbf}
.aqua-background{background:#00fafa}
.black{color:#000}
.black-background{background:#000}
.blue{color:#0000bf}
.blue-background{background:#0000fa}
.fuchsia{color:#bf00bf}
.fuchsia-background{background:#fa00fa}
.gray{color:#606060}
.gray-background{background:#7d7d7d}
.green{color:#006000}
.green-background{background:#007d00}
.lime{color:#00bf00}
.lime-background{background:#00fa00}
.maroon{color:#600000}
.maroon-background{background:#7d0000}
.navy{color:#000060}
.navy-background{background:#00007d}
.olive{color:#606000}
.olive-background{background:#7d7d00}
.purple{color:#600060}
.purple-background{background:#7d007d}
.red{color:#bf0000}
.red-background{background:#fa0000}
.silver{color:#909090}
.silver-background{background:#bcbcbc}
.teal{color:#006060}
.teal-background{background:#007d7d}
.white{color:#bfbfbf}
.white-background{background:#fafafa}
.yellow{color:#bfbf00}
.yellow-background{background:#fafa00}
span.icon>.fa{cursor:default}
a span.icon>.fa{cursor:inherit}
.admonitionblock td.icon [class^="fa icon-"]{font-size:2.5em;text-shadow:1px 1px 2px rgba(0,0,0,.5);cursor:default}
.admonitionblock td.icon .icon-note::before{content:"\f05a";color:#19407c}
.admonitionblock td.icon .icon-tip::before{content:"\f0eb";text-shadow:1px 1px 2px rgba(155,155,0,.8);color:#111}
.admonitionblock td.icon .icon-warning::before{content:"\f071";color:#bf6900}
.admonitionblock td.icon .icon-caution::before{content:"\f06d";color:#bf3400}
.admonitionblock td.icon .icon-important::before{content:"\f06a";color:#bf0000}
.conum[data-value]{display:inline-block;color:#fff!important;background:rgba(0,0,0,.8);border-radius:50%;text-align:center;font-size:.75em;width:1.67em;height:1.67em;line-height:1.67em;font-family:"Open Sans","DejaVu Sans",sans-serif;font-style:normal;font-weight:bold}
.conum[data-value] *{color:#fff!important}
.conum[data-value]+b{display:none}
.conum[data-value]::after{content:attr(data-value)}
pre .conum[data-value]{position:relative;top:-.125em}
b.conum *{color:inherit!important}
.conum:not([data-value]):empty{display:none}
dt,th.tableblock,td.content,div.footnote{text-rendering:optimizeLegibility}
h1,h2,p,td.content,span.alt,summary{letter-spacing:-.01em}
p strong,td.content strong,div.footnote strong{letter-spacing:-.005em}
p,blockquote,dt,td.content,td.hdlist1,span.alt,summary{font-size:1.0625rem}
p{margin-bottom:1.25rem}
.sidebarblock p,.sidebarblock dt,.sidebarblock td.content,p.tableblock{font-size:1em}
.exampleblock>.content{background:#fffef7;border-color:#e0e0dc;box-shadow:0 1px 4px #e0e0dc}
.print-only{display:none!important}
@page{margin:1.25cm .75cm}
@media print{*{box-shadow:none!important;text-shadow:none!important}
html{font-size:80%}
a{color:inherit!important;text-decoration:underline!important}
a.bare,a[href^="#"],a[href^="mailto:"]{text-decoration:none!important}
a[href^="http:"]:not(.bare)::after,a[href^="https:"]:not(.bare)::after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em}
abbr[title]{border-bottom:1px dotted}
abbr[title]::after{content:" (" attr(title) ")"}
pre,blockquote,tr,img,object,svg{page-break-inside:avoid}
thead{display:table-header-group}
svg{max-width:100%}
p,blockquote,dt,td.content{font-size:1em;orphans:3;widows:3}
h2,h3,#toctitle,.sidebarblock>.content>.title{page-break-after:avoid}
#header,#content,#footnotes,#footer{max-width:none}
#toc,.sidebarblock,.exampleblock>.content{background:none!important}
#toc{border-bottom:1px solid #dddddf!important;padding-bottom:0!important}
body.book #header{text-align:center}
body.book #header>h1:first-child{border:0!important;margin:2.5em 0 1em}
body.book #header .details{border:0!important;display:block;padding:0!important}
body.book #header .details span:first-child{margin-left:0!important}
body.book #header .details br{display:block}
body.book #header .details br+span::before{content:none!important}
body.book #toc{border:0!important;text-align:left!important;padding:0!important;margin:0!important}
body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-break-before:always}
.listingblock code[data-lang]::before{display:block}
#footer{padding:0 .9375em}
.hide-on-print{display:none!important}
.print-only{display:block!important}
.hide-for-print{display:none!important}
.show-for-print{display:inherit!important}}
@media amzn-kf8,print{#header>h1:first-child{margin-top:1.25rem}
.sect1{padding:0!important}
.sect1+.sect1{border:0}
#footer{background:none}
#footer-text{color:rgba(0,0,0,.6);font-size:.9em}}
@media amzn-kf8{#header,#content,#footnotes,#footer{padding:0}}
</style>
</head>
<body class="article toc2 toc-left">
<div id="header">
<h1>fok-js使用手册</h1>
<div id="toc" class="toc2">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="#_array_数组">array 数组</a>
<ul class="sectlevel2">
<li><a href="#_arraycompact_过滤空值">arrayCompact 过滤空值</a></li>
<li><a href="#_arraydeduplication_数组去重">arrayDeduplication 数组去重</a></li>
<li><a href="#_arrayflattendeep_拉平多维数组">arrayFlattenDeep 拉平多维数组</a></li>
<li><a href="#_arraypull_删除元素">arrayPull 删除元素</a></li>
<li><a href="#_arraypullall_删除数组元素">arrayPullAll 删除数组元素</a></li>
<li><a href="#_arrayunion_数组取并集">arrayUnion 数组取并集</a></li>
</ul>
</li>
<li><a href="#_class">class</a>
<ul class="sectlevel2">
<li><a href="#_addclass_为元素添加class">addClass 为元素添加class</a></li>
<li><a href="#_hasclass_判断元素是否有某个class">hasClass 判断元素是否有某个class</a></li>
<li><a href="#_removeclass_为元素移除class">removeClass 为元素移除class</a></li>
</ul>
</li>
<li><a href="#_color">color</a>
<ul class="sectlevel2">
<li><a href="#_elestylevalue_获取元素指定样式值">eleStyleValue 获取元素指定样式值</a></li>
<li><a href="#_hextorgb_将十六进制颜色值转换为rgb颜色值">hexToRGB 将十六进制颜色值转换为RGB颜色值</a></li>
<li><a href="#_rgbtohex_将rgb颜色值转换为十六进制颜色值">rgbToHex 将RGB颜色值转换为十六进制颜色值</a></li>
</ul>
</li>
<li><a href="#_convert_转换">convert 转换</a>
<ul class="sectlevel2">
<li><a href="#_base64urltoblob_将base64图片url转换为blob流">base64UrlToBlob 将base64图片URL转换为Blob流</a></li>
<li><a href="#_blobtobase64_将blob流转换为base64图片url">blobToBase64 将Blob流转换为base64图片URL</a></li>
</ul>
</li>
<li><a href="#_cookie">cookie</a>
<ul class="sectlevel2">
<li><a href="#_getcookie_根据name读取cookie">getCookie 根据name读取cookie</a></li>
<li><a href="#_removecookie_根据name删除cookie">removeCookie 根据name删除cookie</a></li>
<li><a href="#_setcookie_设置cookie">setCookie 设置Cookie</a></li>
</ul>
</li>
<li><a href="#_decimal_精度运算">Decimal 精度运算</a>
<ul class="sectlevel2">
<li><a href="#_加">加</a></li>
<li><a href="#_减">减</a></li>
<li><a href="#_乘">乘</a></li>
<li><a href="#_除">除</a></li>
<li><a href="#_注意">注意</a></li>
<li><a href="#_小数位">小数位</a></li>
</ul>
</li>
<li><a href="#_device_硬件">device 硬件</a>
<ul class="sectlevel2">
<li><a href="#_getexplore_获取浏览器类型和版本">getExplore 获取浏览器类型和版本</a></li>
<li><a href="#_getos_获取操作系统类型">getOS 获取操作系统类型</a></li>
</ul>
</li>
<li><a href="#_dom_元素">dom 元素</a>
<ul class="sectlevel2">
<li><a href="#_getparents_获取指定class的父节点">getParents 获取指定class的父节点</a></li>
<li><a href="#_getscrolltop_获取滚动条距顶部的距离">getScrollTop 获取滚动条距顶部的距离</a></li>
<li><a href="#_offset_获取一个元素的距离文档document的位置">offset 获取一个元素的距离文档(document)的位置</a></li>
<li><a href="#_scrollto_在duration时间内滚动条滚动到to指定位置">scrollTo 在${duration}时间内，滚动条滚动到${to}指定位置</a></li>
<li><a href="#_setscrolltop_设置滚动条距顶部的距离">setScrollTop 设置滚动条距顶部的距离</a></li>
</ul>
</li>
<li><a href="#_file_文件">file 文件</a>
<ul class="sectlevel3">
<li><a href="#_blobdownload_blob文件下载">blobDownload blob文件下载</a></li>
</ul>
</li>
<li><a href="#_format_格式">format 格式</a>
<ul class="sectlevel2">
<li><a href="#_formatnumbertomonetization_数字货币化千分位">formatNumberToMonetization 数字货币化千分位</a></li>
<li><a href="#_formatnumbertothousand_数字千分位">formatNumberToThousand 数字千分位</a></li>
</ul>
</li>
<li><a href="#_function_函数">function 函数</a>
<ul class="sectlevel2">
<li><a href="#_debounce_防抖">debounce 防抖</a></li>
<li><a href="#_throttle_节流">throttle 节流</a></li>
</ul>
</li>
<li><a href="#_keycode">keycode</a>
<ul class="sectlevel2">
<li><a href="#_getkeyname_根据keycode获得键名">getKeyName 根据keycode获得键名</a></li>
</ul>
</li>
<li><a href="#_object_对象">object 对象</a>
<ul class="sectlevel2">
<li><a href="#_hasownprop_判断对象自身属性中是否具有指定的属性">hasOwnProp 判断对象自身属性中是否具有指定的属性</a></li>
<li><a href="#_hasownval_判断对象是否包含该值">hasOwnVal 判断对象是否包含该值</a></li>
<li><a href="#_isemptyobject_判断对象是否为空">isEmptyObject 判断对象是否为空</a></li>
</ul>
</li>
<li><a href="#_pinyin_拼音">pinyin 拼音</a>
<ul class="sectlevel2">
<li><a href="#_topinyin_生成拼音码">toPinyin 生成拼音码</a></li>
<li><a href="#_tofirstletters_获取字符串首字母">toFirstLetters 获取字符串首字母</a></li>
</ul>
</li>
<li><a href="#_print_打印">print 打印</a>
<ul class="sectlevel2">
<li><a href="#_print_打印_2">print 打印</a></li>
</ul>
</li>
<li><a href="#_random_随机生成">random 随机生成</a>
<ul class="sectlevel2">
<li><a href="#_randomcolor_随机生成颜色">randomColor 随机生成颜色</a></li>
<li><a href="#_randomnum_生成指定范围的随机整数">randomNum 生成指定范围的随机整数</a></li>
<li><a href="#_randomstr_生成指定位数的随机字符串">randomStr 生成指定位数的随机字符串</a></li>
<li><a href="#_randomcname_生成中文名字">randomCName 生成中文名字</a></li>
<li><a href="#_areatree_地区树">areaTree 地区树</a></li>
<li><a href="#_randomarea_生成地区">randomArea 生成地区</a></li>
<li><a href="#_randombirth_生成出生日期">randomBirth 生成出生日期</a></li>
<li><a href="#_randomidcard_生成身份证">randomIdCard 生成身份证</a></li>
<li><a href="#_randomemail_生成邮箱地址">randomEmail 生成邮箱地址</a></li>
</ul>
</li>
<li><a href="#_regexp_正则">regexp 正则</a>
<ul class="sectlevel2">
<li><a href="#_iscolor_是否为颜色值">isColor 是否为颜色值</a></li>
<li><a href="#_isemail_是否为邮箱">isEmail 是否为邮箱</a></li>
<li><a href="#_ishexcolor_是否为16进制颜色值">isHexColor 是否为16进制颜色值</a></li>
<li><a href="#_isidcard_是否为身份证号">isIdCard 是否为身份证号</a></li>
<li><a href="#_isip_判断是否为ip地址">isIp 判断是否为ip地址</a></li>
<li><a href="#_isphoneno_判断是否为手机号">isPhoneNo 判断是否为手机号</a></li>
<li><a href="#_ispositiveinteger_判断是否为正整数">isPositiveInteger 判断是否为正整数</a></li>
<li><a href="#_istelephoneno_判断是否为座机号">istelephoneNo 判断是否为座机号</a></li>
<li><a href="#_isurl_判断是否为url地址">isUrl 判断是否为URL地址</a></li>
</ul>
</li>
<li><a href="#_storage_缓存">storage 缓存</a>
<ul class="sectlevel2">
<li><a href="#_getlocal_获取localstorage值">getLocal 获取localstorage值</a></li>
<li><a href="#_setlocal_设置localstorage值">setLocal 设置localstorage值</a></li>
<li><a href="#_getsession_获取sessionstorage值">getSession 获取sessionstorage值</a></li>
<li><a href="#_setsession_设置sessionstorage值">setSession 设置sessionstorage值</a></li>
<li><a href="#_removelocal_删除localstorage值">removeLocal 删除localstorage值</a></li>
<li><a href="#_removesession_删除sessionstorage值">removeSession 删除sessionstorage值</a></li>
<li><a href="#_clearlocal_删除全部localstorage值">clearLocal 删除全部localstorage值</a></li>
<li><a href="#_clearsession_删除全部sessionstorage值">clearSession 删除全部sessionstorage值</a></li>
<li><a href="#_clearall_删除全部localstorage和sessionstorage值">clearAll 删除全部localstorage和sessionstorage值</a></li>
</ul>
</li>
<li><a href="#_string_字符串">string 字符串</a>
<ul class="sectlevel2">
<li><a href="#_camelcase_转驼峰">camelCase 转驼峰</a></li>
<li><a href="#_deduplication_字符串去重">deduplication 字符串去重</a></li>
<li><a href="#_digituppercase_金额小写转大写">digitUppercase 金额小写转大写</a></li>
<li><a href="#_ishasillegalchar_检测是否包含非法字符">isHasIllegalChar 检测是否包含非法字符</a></li>
<li><a href="#_kebabcase_转烤肉串">kebabCase 转烤肉串</a></li>
<li><a href="#_snakecase_转下划线">snakeCase 转下划线</a></li>
<li><a href="#_upperfirst_转首字母大写">upperFirst 转首字母大写</a></li>
</ul>
</li>
<li><a href="#_support">support</a>
<ul class="sectlevel2">
<li><a href="#_issupportwebp_判断浏览器是否支持webp格式图片">isSupportWebP 判断浏览器是否支持webP格式图片</a></li>
</ul>
</li>
<li><a href="#_time_时间">time 时间</a>
<ul class="sectlevel2">
<li><a href="#_获取时间实例">获取时间实例</a></li>
<li><a href="#_获取毫秒">获取毫秒</a></li>
<li><a href="#_获取秒">获取秒</a></li>
<li><a href="#_获取分钟">获取分钟</a></li>
<li><a href="#_获取小时">获取小时</a></li>
<li><a href="#_获取日期">获取日期</a></li>
<li><a href="#_获取星期">获取星期</a></li>
<li><a href="#_获取月">获取月</a></li>
<li><a href="#_获取年">获取年</a></li>
<li><a href="#_设置时间">设置时间</a></li>
<li><a href="#_时间相加">时间相加</a></li>
<li><a href="#_时间相减">时间相减</a></li>
<li><a href="#_时间加减链式调用">时间加减链式调用</a></li>
<li><a href="#_格式化">格式化</a></li>
<li><a href="#_判断是否为闰年">判断是否为闰年</a></li>
<li><a href="#_formatpasstime_格式化距现在的已过时间">formatPassTime 格式化距现在的已过时间</a></li>
<li><a href="#_formatremaintime_格式化现在距指定时间的剩余时间">formatRemainTime 格式化现在距指定时间的剩余时间</a></li>
<li><a href="#_formattimestamp_时间戳格式化">formatTimeStamp 时间戳格式化</a></li>
<li><a href="#_getafterdays_获取某天之后的几天">getAfterDays 获取某天之后的几天</a></li>
<li><a href="#_getbeforedays_获取某天之前的几天">getBeforeDays 获取某天之前的几天</a></li>
<li><a href="#_getlastweek_获取上周">getLastWeek 获取上周</a></li>
<li><a href="#_getnextweek_获取下周">getNextWeek 获取下周</a></li>
<li><a href="#_getthisweek_获取本周">getThisWeek 获取本周</a></li>
<li><a href="#_monthdays_获取指定月份的天数">monthDays 获取指定月份的天数</a></li>
<li><a href="#_timeleft_计算剩余时间">timeLeft 计算剩余时间</a></li>
</ul>
</li>
<li><a href="#_tools_工具">tools 工具</a>
<ul class="sectlevel3">
<li><a href="#_clone_浅拷贝">clone 浅拷贝</a></li>
<li><a href="#_clonedeep_深拷贝">cloneDeep 深拷贝</a></li>
<li><a href="#_eq_是否相等">eq 是否相等</a></li>
<li><a href="#_getagebyidcard_根据身份证号返回年龄">getAgeByIDcard 根据身份证号返回年龄</a></li>
<li><a href="#_getbirthdaybyidcard_根据身份证号返回出生日期">getBirthdayByIDcard 根据身份证号返回出生日期</a></li>
<li><a href="#_getgenderbyidcard_根据身份证号返回性别">getGenderByIDcard 根据身份证号返回性别</a></li>
<li><a href="#_gettypename_获取变量数据类型名称">getTypeName 获取变量数据类型名称</a></li>
<li><a href="#_isarray_是否是数组">isArray 是否是数组</a></li>
<li><a href="#_isboolean_是否是布尔值">isBoolean 是否是布尔值</a></li>
<li><a href="#_isfunction_是否是函数">isFunction 是否是函数</a></li>
<li><a href="#_isnull_是否是null">isNull 是否是null</a></li>
<li><a href="#_isobject_是否是对象">isObject 是否是对象</a></li>
<li><a href="#_isstring_是否是字符串">isString 是否是字符串</a></li>
<li><a href="#_returnlistname_返回下拉列表名称">returnListName 返回下拉列表名称</a></li>
</ul>
</li>
<li><a href="#_url">url</a>
<ul class="sectlevel2">
<li><a href="#_parsequerystring_url参数转对象">parseQueryString url参数转对象</a></li>
<li><a href="#_stringfyquerystring_对象序列化">stringfyQueryString 对象序列化</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="content">
<div class="sect1">
<h2 id="_array_数组">array 数组</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_arraycompact_过滤空值">arrayCompact 过滤空值</h3>
<div class="paragraph">
<p>空值一般为false、null、0、""、undefined、和 NaN。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { arrayCompact } from "fok-js";

console.log(arrayCompact([0, 1, false, 2, '', 3]));
// [1, 2, 3]


############### 源码 #################
/**
 * @desc 去掉数组中的空值
 * @param {Array} array
 * @return {Array}
 */
function arrayCompact(array) {
	let resIndex = 0;
	const result = [];
	if (array == null) {
		return result;
	}
	for (const value of array) {
		if (value) {
			result[resIndex++] = value;
		}
	}
	return result;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_arraydeduplication_数组去重">arrayDeduplication 数组去重</h3>
<div class="paragraph">
<p>删除数组中的重复元素，并返回一个新的数组。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { arrayDeduplication } from "fok-js";

let array = [1, 2, 3, 1, 2, 3];
console.log(arrayDeduplication(array));
// [1, 2, 3]
let array = ['sdf', 'fef', 123, false, 'fef', false];
console.log(arrayDeduplication(array));
// ['sdf', 'fef', 123, false]



############### 源码 #################
/**
 * @desc 数组去除重复数据
 * @param {Array} 要去重的数组
 * @return {Array} 一个新的数组
 */
function arrayDeduplication(myArray) {
	return [...new Set(myArray)];
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_arrayflattendeep_拉平多维数组">arrayFlattenDeep 拉平多维数组</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { arrayFlattenDeep } from "fok-js";

console.log(arrayFlattenDeep([1, [2, [3, [4]], 5]]));
// [1, 2, 3, 4, 5]




############### 源码 #################
const INFINITY = 1 / 0;
/**
 * @desc 将array递归为一维数组
 * @param {Array} array
 * @return {Array} array
 */
function arrayFlattenDeep(array) {
	const length = array == null ? 0 : array.length;
	return length ? baseFlatten(array, INFINITY) : [];
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_arraypull_删除元素">arrayPull 删除元素</h3>
<div class="paragraph">
<p>移除数组array中所有和给定值相等的元素,这个方法会改变数组。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { arrayPull } from "fok-js";

let array = [1, 2, 3, 1, 2, 3];
arrayPull(array, 2, 3);
console.log(array);
// [1, 1]




############### 源码 #################
/**
 * @desc 移除数组array中所有和给定值相等的元素,这个方法会改变数组。
 * @param {Array} 要修改的数组
 * @param {...*} 要删除的值
 * @return {Array}
 */
function arrayPull(array, ...values) {
	return arrayPullAll(array, values);
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_arraypullall_删除数组元素">arrayPullAll 删除数组元素</h3>
<div class="paragraph">
<p>移除数组array中所有和给定数组值相等的元素,这个方法不会改变数组。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { arrayPullAll } from "fok-js";

let array = [1, 2, 3, 1, 2, 3];
arrayPullAll(array, [2, 1]);
console.log(array);
// [3, 3]




############### 源码 #################
/**
 * @desc 移除数组array中所有和给定数组值相等的元素,这个方法不会改变数组。
 * @param {Array} 要修改的数组
 * @param {Array} 要移除值的数组
 * @return {Array}
 */
function arrayPullAll(array, values) {
	return array != null &amp;&amp; array.length &amp;&amp; values != null &amp;&amp; values.length ? basePullAll(array, values) : array;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_arrayunion_数组取并集">arrayUnion 数组取并集</h3>
<div class="paragraph">
<p>创建一个按顺序排列的唯一值的数组。所有给定数组的元素值使用SameValueZero做等值比较。（注： arrays（数组）的并集，按顺序返回，返回数组的元素是唯一的）。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { arrayUnion } from "fok-js";

console.log(arrayUnion([2], [1, 2]));
// [2, 1]</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_class">class</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_addclass_为元素添加class">addClass 为元素添加class</h3>
<div class="listingblock">
<div class="content">
<pre>&lt;template&gt;
  &lt;h2 ref="myH2"&gt;登录&lt;/h2&gt;
&lt;/template&gt;

&lt;script setup&gt;
import { addClass } from "fok-js";
import { ref, onMounted } from 'vue';

const myH2 = ref();
onMounted(() =&gt; {
  addClass(myH2.value, "my-h2");
});
&lt;/script&gt;
&lt;style lang="scss" scoped&gt;
 .my-h2 {
   color: red;
 }
&lt;/style&gt;

运行结果为h2标签增加了my-h2样式，字体变为红色。



############### 源码 #################
/**
 * @desc   为元素添加class
 * @param  {HTMLElement} ele
 * @param  {String} cls
 */
function addClass(ele, cls) {
    if (!hasClass(ele, cls)) {
        ele.className += ' ' + cls;
    }
}</pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_hasclass_判断元素是否有某个class">hasClass 判断元素是否有某个class</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">&lt;template&gt;
  &lt;h2 ref="myH2"&gt;登录&lt;/h2&gt;
&lt;/template&gt;

&lt;script setup&gt;
import { addClass, hasClass } from "fok-js";
import { ref, onMounted } from 'vue';

const myH2 = ref();
onMounted(() =&gt; {
  console.log(hasClass(myH2.value, "my-h2"));
  //false
  addClass(myH2.value, "my-h2");
  console.log(hasClass(myH2.value, "my-h2"));
  //true
});
&lt;/script&gt;
&lt;style lang="scss" scoped&gt;
 .my-h2 {
   color: red;
 }
&lt;/style&gt;



############### 源码 #################
/**
 * @desc 判断元素是否有某个class
 * @param {HTMLElement} ele
 * @param {String} cls
 * @return {Boolean}
 */
function hasClass(ele, cls) {
    return (new RegExp('(\\s|^)' + cls + '(\\s|$)')).test(ele.className);
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_removeclass_为元素移除class">removeClass 为元素移除class</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">&lt;template&gt;
  &lt;h2 ref="myH2"&gt;登录&lt;/h2&gt;
&lt;/template&gt;

&lt;script setup&gt;
import { addClass, removeClass } from "fok-js";
import { ref, onMounted } from 'vue';

const myH2 = ref();
onMounted(() =&gt; {
  addClass(myH2.value, "my-h2");
  removeClass(myH2.value, "my-h2");
});
&lt;/script&gt;
&lt;style lang="scss" scoped&gt;
 .my-h2 {
   color: red;
 }
&lt;/style&gt;
运行结果为h2标签增加了my-h2样式，然后被移除，字体还是黑色。



############### 源码 #################
/**
 * @desc 为元素移除class
 * @param {HTMLElement} ele
 * @param {String} cls
 */
function removeClass(ele, cls) {
    if (hasClass(ele, cls)) {
        let reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
        ele.className = ele.className.replace(reg, ' ');
    }
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_color">color</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_elestylevalue_获取元素指定样式值">eleStyleValue 获取元素指定样式值</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">&lt;template&gt;
  &lt;h2 ref="myH2"&gt;登录&lt;/h2&gt;
&lt;/template&gt;

&lt;script setup&gt;
import { addClass, eleStyleValue } from "fok-js";
import { ref, onMounted } from 'vue';

const myH2 = ref();
onMounted(() =&gt; {
  console.log(eleStyleValue(myH2.value, "color"));
  //rgba(0, 0, 0, 0.85)
  addClass(myH2.value, "my-h2");
  console.log(eleStyleValue(myH2.value, "color"));
  //rgb(255, 0, 0)
  console.log(eleStyleValue(myH2.value, "font-size"));
  //21px
});
&lt;/script&gt;
&lt;style lang="scss" scoped&gt;
 .my-h2 {
   color: red;
 }
&lt;/style&gt;



############### 源码 #################
/**
 * @desc    获取元素指定样式值
 * @param   {HTMLElement} ele 用于获取计算样式的Element
 * @param   {String} styleName 样式名称
 * @return  {String}
 */
function eleStyleValue(ele, styleName) {
  const cs = ele &amp;&amp; window.getComputedStyle &amp;&amp; window.getComputedStyle(ele, null);
  return cs[styleName];
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_hextorgb_将十六进制颜色值转换为rgb颜色值">hexToRGB 将十六进制颜色值转换为RGB颜色值</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { hexToRGB } from "fok-js";

console.log(hexToRGB("#1a2b3c"));
//rgb(26, 43, 60)
console.log(hexToRGB("000000"));
//rgb(0, 0, 0)



############### 源码 #################
/**
 * @desc    将 HEX 颜色转换为其 RGB 表示
 * @param   {string} hex 要转换的颜色
 * @return  {string} 传递颜色的 RGB 表示
 */
function hexToRGB(hex) {
  // 去除可能存在的 # 号
	hex = hex.replace(/^#/, '');
	// 将 hex 值拆分为 R、G、B 部分
	let bigint = parseInt(hex, 16);
	let r = (bigint &gt;&gt; 16) &amp; 255;
	let g = (bigint &gt;&gt; 8) &amp; 255;
	let b = bigint &amp; 255;
	// 返回 RGB 颜色值
	return `rgb(${r}, ${g}, ${b})`;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_rgbtohex_将rgb颜色值转换为十六进制颜色值">rgbToHex 将RGB颜色值转换为十六进制颜色值</h3>
<div class="paragraph">
<p>r, g, 和 b 需要在 [0, 255] 范围内。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { rgbToHex } from "fok-js";

console.log(rgbToHex(255, 0, 0));
//#ff0000
console.log(rgbToHex(123, 123, 123));
//#7b7b7b



############### 源码 #################
/**
 * @desc   RGB 颜色值转换为 十六进制颜色值.
 *         r, g, 和 b 需要在 [0, 255] 范围内
 *
 * @param   {number} r
 * @param   {number} g
 * @param   {number} b
 * @return  {String}    类似#ff00ff
 */
function rgbToHex(r, g, b) {
  // tslint:disable-next-line:no-bitwise
  const hex = ((r &lt;&lt; 16) | (g &lt;&lt; 8) | b).toString(16)
  return '#' + new Array(Math.abs(hex.length - 7)).join('0') + hex
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_convert_转换">convert 转换</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_base64urltoblob_将base64图片url转换为blob流">base64UrlToBlob 将base64图片URL转换为Blob流</h3>
<div class="listingblock">
<div class="content">
<pre>import { base64UrlToBlob } from "fok-js";

let base64Img = '';
console.log(`output-&gt;`, base64UrlToBlob(base64Img));
返回一个Blob对象，Blob{size: 306, type: "image/png"}。




############### 源码 #################
/**
 * @desc    将以base64的图片URL的转换为Blob
 * @param   {String} urlData
 * @param   {String} blobType 默认 图片格式 'image/png'
 * @return  {Blob}
 */
function base64UrlToBlob(urlData, blobType = 'image/png') {
  // 去掉头，并转换为byte
  const bytes = urlData &amp;&amp; window.atob(urlData.split(',')[1]);

  // 处理异常,将ascii码小于0的转换为大于0
  const ab = new ArrayBuffer(bytes.length);
  const ia = new Uint8Array(ab);
  for (let i = 0; i &lt; bytes.length; i++) {
    ia[i] = bytes.charCodeAt(i);
  }
  return new Blob([ab], { type: blobType });
}</pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_blobtobase64_将blob流转换为base64图片url">blobToBase64 将Blob流转换为base64图片URL</h3>
<div class="listingblock">
<div class="content">
<pre>import { blobToBase64 } from "fok-js";

let base64Img = '';
let callBackFn = (data) =&gt; {
  console.log(`data-&gt;`, data);
};
blobToBase64(base64UrlToBlob(base64Img), callBackFn);
//




############### 源码 #################
/**
 * @desc    blob流转换为base64     注意：建议使用 fileToBase64 方法
 * @param   {Blob} blob
 * @param   {Function} callback
 */
function blobToBase64(blob, callback) {
  const reader = new FileReader()
  reader.readAsDataURL(blob)
  reader.onload = e =&gt; {
    callback(e.target.result)
  }
}</pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_cookie">cookie</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_getcookie_根据name读取cookie">getCookie 根据name读取cookie</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getCookie } from 'fok-js';

console.log(getCookie("myCookie"));




############### 源码 #################
/**
 * @desc 根据name读取cookie
 * @param  {String} name
 * @return {String}
 */
function getCookie(name) {
    let arr = document.cookie.replace(/\s/g, "").split(';');
    for (let i = 0; i &lt; arr.length; i++) {
        let tempArr = arr[i].split('=');
        if (tempArr[0] == name) {
            return decodeURIComponent(tempArr[1]);
        }
    }
    return '';
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_removecookie_根据name删除cookie">removeCookie 根据name删除cookie</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getCookie, setCookie, removeCookie } from 'fok-js';

removeCookie('myCookie');
console.log(getCookie("myCookie"));
// ' '
setCookie('myCookie', '13sdf', 10);
console.log(getCookie("myCookie"));
// '13sdf'
removeCookie('myCookie');
// ' '




############### 源码 #################
/**
 * @desc 根据name删除cookie
 * @param  {String} name
 */
function removeCookie(name) {
    // 设置已过期，系统会立刻删除cookie
    setCookie(name, '1', -1);
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_setcookie_设置cookie">setCookie 设置Cookie</h3>
<div class="paragraph">
<p>参数分别为name、value和days（过期时间）。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getCookie, setCookie } from 'fok-js';

setCookie('myCookie', '13sdf', 10);
console.log(getCookie("myCookie"));
// '13sdf'



############### 源码 #################
/**
 * @desc  设置Cookie
 * @param {String} name
 * @param {String} value
 * @param {Number} days
 */
function setCookie(name, value, days) {
    let date = new Date();
    date.setDate(date.getDate() + days);
    document.cookie = name + '=' + value + ';expires=' + date + ';path=/';
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_decimal_精度运算">Decimal 精度运算</h2>
<div class="sectionbody">
<div class="paragraph">
<p>想必大家在用js 处理 数字的 加减乘除的时候，或许都有遇到过 精度不够的问题</p>
</div>
<div class="paragraph">
<p>还有那些经典的面试题 02+0.1 == 0.3</p>
</div>
<div class="paragraph">
<p>至于原因，那就是 js 计算底层用的 是 ，精度上有限制</p>
</div>
<div class="paragraph">
<p>那么，Decimal.js 就是帮助我们解决 js中的精度失准的问题</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { Decimal } from "fok-js";</code></pre>
</div>
</div>
<div class="sect2">
<h3 id="_加">加</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">let a = 1
let b = 6
// a 与 b 可以是 任何类型，Decimal 内部会自己处理兼容
// 下面两种都可以 可以带 new 也不可以不带 new
let res = new Decimal(a).add(new Decimal(b))
let res = Decimal(a).add(Decimal(b))</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_减">减</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">let a = "4"
let b = "8"
// a 与 b 可以是 任何类型，Decimal 内部会自己处理兼容
// 下面两种都可以 可以带 new 也不可以不带 new
let res = new Decimal(a).sub(new Decimal(b))
let res = Decimal(a).sub(Decimal(b))</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_乘">乘</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">let a = 1
let b = 6
// a 与 b 可以是 任何类型，Decimal 内部会自己处理兼容
// 下面两种都可以 可以带 new 也不可以不带 new
let res = new Decimal(a).mul(new Decimal(b))
let res = Decimal(a).mul(Decimal(b))</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_除">除</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">let a = 1
let b = 6
// a 与 b 可以是 任何类型，Decimal 内部会自己处理兼容
// 下面两种都可以 可以带 new 也不可以不带 new
let res = new Decimal(a).div(new Decimal(b))
let res = Decimal(a).div(Decimal(b))</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_注意">注意</h3>
<div class="paragraph">
<p>上面的结果是 一个 Decimal 对象，你可以转换成 Number 或则 String</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">let res = Decimal(a).div(Decimal(b)).toNumber()  // 结果转换成 Number
let res = Decimal(a).div(Decimal(b)).toString()  // 结果转换成 String</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_小数位">小数位</h3>
<div class="paragraph">
<p>上面的结果是 一个 Decimal 对象，你可以转换成 Number 或则 String</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">//查看有几位小数 (注意不计算 小数点 最后 末尾 的 0)
y = new Decimal(987000.000)
y.sd()                                   // '3' 有效位数
y.sd(true)                               // '6' 总共位数

// 保留 多少个位数 （小数位 会补0）
x = 45.6
x.toPrecision(5)                         // '45.600'

// 保留 多少位有效位数（小数位 不会补0，是计算的有效位数）
x = new Decimal(9876.5)
x.toSignificantDigits(6)                 // '9876.5' 不会补0 只是针对有效位数

// 保留几位小数 , 跟 js 中的 number 一样
toFixed
x = 3.456
// 向下取整
x.toFixed(2, Decimal.ROUND_DOWN)  // '3.45' (舍入模式 向上0 向下1 四舍五入 4，7)
// 向上取整
Decimal.ROUND_UP

//四舍五入
ROUND_HALF_UP</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_device_硬件">device 硬件</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_getexplore_获取浏览器类型和版本">getExplore 获取浏览器类型和版本</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getExplore } from "fok-js";

console.log(getExplore());
//Chrome: 120.0.0.0



############### 源码 #################
/**
 * @desc 获取浏览器类型和版本
 * @return {String}
 */
function getExplore() {
    let sys = {},
        ua = navigator.userAgent.toLowerCase(),
        s;
    (s = ua.match(/rv:([\d.]+)\) like gecko/)) ? sys.ie = s[1]:
        (s = ua.match(/msie ([\d\.]+)/)) ? sys.ie = s[1] :
        (s = ua.match(/edge\/([\d\.]+)/)) ? sys.edge = s[1] :
        (s = ua.match(/firefox\/([\d\.]+)/)) ? sys.firefox = s[1] :
        (s = ua.match(/(?:opera|opr).([\d\.]+)/)) ? sys.opera = s[1] :
        (s = ua.match(/chrome\/([\d\.]+)/)) ? sys.chrome = s[1] :
        (s = ua.match(/version\/([\d\.]+).*safari/)) ? sys.safari = s[1] : 0;
    // 根据关系进行判断
    if (sys.ie) return ('IE: ' + sys.ie)
    if (sys.edge) return ('EDGE: ' + sys.edge)
    if (sys.firefox) return ('Firefox: ' + sys.firefox)
    if (sys.chrome) return ('Chrome: ' + sys.chrome)
    if (sys.opera) return ('Opera: ' + sys.opera)
    if (sys.safari) return ('Safari: ' + sys.safari)
    return 'Unkonwn'
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_getos_获取操作系统类型">getOS 获取操作系统类型</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getOS } from "fok-js";

console.log(getOS());
//windows



############### 源码 #################
/**
 * @desc 获取操作系统类型
 * @return {String}
 */
function getOS() {
    let userAgent = 'navigator' in window &amp;&amp; 'userAgent' in navigator &amp;&amp; navigator.userAgent.toLowerCase() || '';
    let vendor = 'navigator' in window &amp;&amp; 'vendor' in navigator &amp;&amp; navigator.vendor.toLowerCase() || '';
    let appVersion = 'navigator' in window &amp;&amp; 'appVersion' in navigator &amp;&amp; navigator.appVersion.toLowerCase() || '';

    if (/iphone/i.test(userAgent) || /ipad/i.test(userAgent) || /ipod/i.test(userAgent)) return 'ios'
    if (/android/i.test(userAgent)) return 'android'
    if (/win/i.test(appVersion) &amp;&amp; /phone/i.test(userAgent)) return 'windowsPhone'
    if (/mac/i.test(appVersion)) return 'MacOSX'
    if (/win/i.test(appVersion)) return 'windows'
    if (/linux/i.test(appVersion)) return 'linux'
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_dom_元素">dom 元素</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_getparents_获取指定class的父节点">getParents 获取指定class的父节点</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">############### 源码 #################
/**
 * 获取指定class的父节点
 * @param {HTMLElement} element
 * @param {String} className
 */
function getParents(element, className) {
  //dom.getAttribute('class')==dom.className，两者等价
  var returnParentElement = null;
  function getpNode(element, className) {
    //创建父级节点的类数组
    let pClassList = element.parentNode.getAttribute('class');
    let pNode = element.parentNode;
    if (!pClassList) {
      //如果未找到类名数组，就是父类无类名，则再次递归
      getpNode(pNode, className);
    } else if (pClassList &amp;&amp; pClassList.indexOf(className) &lt; 0) {
      //如果父类的类名中没有预期类名，则再次递归
      getpNode(pNode, className);
    } else if (pClassList &amp;&amp; pClassList.indexOf(className) &gt; -1) {
      returnParentElement = pNode;
    }
  }
  getpNode(element, className);
  //console.log(returnParentElement);
  return returnParentElement;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_getscrolltop_获取滚动条距顶部的距离">getScrollTop 获取滚动条距顶部的距离</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getScrollTop } from 'fok-utils';

console.log(getScrollTop());
// 0



############### 源码 #################
/**
 * @desc 获取滚动条距顶部的距离
 */
function getScrollTop() {
    return (document.documentElement &amp;&amp; document.documentElement.scrollTop) || document.body.scrollTop;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_offset_获取一个元素的距离文档document的位置">offset 获取一个元素的距离文档(document)的位置</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">&lt;template&gt;
  &lt;div&gt;
    &lt;h2 ref="myH2"&gt;登录&lt;/h2&gt;
  &lt;/div&gt;
&lt;/template&gt;

&lt;script setup&gt;
  import { offset } from 'fok-utils';
  import { ref, onMounted } from 'vue';

  const myH2 = ref(null);
  onMounted(() =&gt; {
    console.log(offset(myH2.value));
    //{left: 0, top: 0}
  });
&lt;/script&gt;



############### 源码 #################
/**
 * @desc  获取一个元素的距离文档(document)的位置，类似jQ中的offset()
 * @param {HTMLElement} ele
 * @returns { {left: number, top: number} }
 */
function offset(ele) {
    let pos = {
        left: 0,
        top: 0
    };
    while (ele) {
        pos.left += ele.offsetLeft;
        pos.top += ele.offsetTop;
        ele = ele.offsetParent;
    };
    return pos;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_scrollto_在duration时间内滚动条滚动到to指定位置">scrollTo 在${duration}时间内，滚动条滚动到${to}指定位置</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">&lt;template&gt;
  &lt;div style="height: 1500px; width: 100%;"&gt;&lt;/div&gt;
&lt;/template&gt;

&lt;script setup&gt;
  import { scrollTo } from 'fok-utils';

  scrollTo(500, 1000 * 2);
  // 效果为在2秒时间内，垂直滚动条平滑滚动到500位置。
&lt;/script&gt;





############### 源码 #################
let requestAnimFrame = (function () {
    return function (callback) {
            callback &amp;&amp; window.setTimeout(callback, 1000 / 60);
        };
})();
/**
 * @desc  在${duration}时间内，滚动条平滑滚动到${to}指定位置
 * @param {Number} to
 * @param {Number} duration
 */
function scrollTo(to, duration) {
    if (duration &lt; 0) {
        setScrollTop(to);
        return
    }
    let diff = to - getScrollTop();
    if (diff === 0) return
    let step = diff / duration * 10;
    requestAnimFrame(
        function () {
            if (Math.abs(step) &gt; Math.abs(diff)) {
                setScrollTop(getScrollTop() + diff);
                return;
            }
            setScrollTop(getScrollTop() + step);
            if (diff &gt; 0 &amp;&amp; getScrollTop() &gt;= to || diff &lt; 0 &amp;&amp; getScrollTop() &lt;= to) {
                return;
            }
            scrollTo(to, duration - 16);
        });
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_setscrolltop_设置滚动条距顶部的距离">setScrollTop 设置滚动条距顶部的距离</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">&lt;template&gt;
  &lt;div style="height: 1500px; width: 100%;"&gt;&lt;/div&gt;
&lt;/template&gt;

&lt;script setup&gt;
  import { scrollTo } from 'fok-utils';
  import { onMounted } from 'vue';

  onMounted(() =&gt; {
    setScrollTop(200);
  });
&lt;/script&gt;
效果为垂直滚动条直接定位到200位置。



############### 源码 #################
/**
 * @desc 设置滚动条距顶部的距离
 * @param {Number} value
 */
function setScrollTop(value) {
	if (value) {
		window.scrollTo(0, value);
	}
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_file_文件">file 文件</h2>
<div class="sectionbody">
<div class="sect3">
<h4 id="_blobdownload_blob文件下载">blobDownload blob文件下载</h4>
<table class="tableblock frame-all grid-all fit-content">
<caption class="title">Table 1. blobDownload参数</caption>
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名称</th>
<th class="tableblock halign-left valign-top">类型</th>
<th class="tableblock halign-left valign-top">说明</th>
<th class="tableblock halign-left valign-top">是否必传</th>
<th class="tableblock halign-left valign-top">默认值</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">fileData</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">二进制</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">需下载文件的二进制</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">是</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">flieType</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">String</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">需要保存的文件类型，可选值见下</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">否</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">xlsx</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">fileName</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">String</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">文件名</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">否</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">未命名文件</p></td>
</tr>
</tbody>
</table>
<table class="tableblock frame-all grid-all fit-content">
<caption class="title">Table 2. flieType可选值</caption>
<colgroup>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">值</th>
<th class="tableblock halign-left valign-top">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">xlsx</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.xlsx文件</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">pdf</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.pdf文件</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">doc</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.doc文件</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">docx</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.docx文件</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">xls</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.xls文件</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">ppt</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.ppt文件</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">pptx</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.pptx文件</p></td>
</tr>
</tbody>
</table>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { blobDownload } from "fok-js";

expenseExport(reqObj) //请求方法
  .then((res) =&gt; {
    blobDownload(res); //使用默认类型和默认名下载.xlsx格式文件
    blobDownload(res, 'pptx', 'pptx文件'); //指定文件类型和文件名下载.pptx格式文件
  });





############### 源码 #################
/**
 * @desc    blob文件下载
 * @param {Blob} fileData
 * @param {String} fileName 下载文件名称指定
 */
function blobDownload(fileData, flieType = 'xlsx', fileName = '未命名文件') {
	if (!fileData) {
		return;
	}
	let flieTypeObj = {};
	if (flieType === 'xlsx') {
		flieTypeObj.type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
	} else if (flieType === 'pdf') {
		flieTypeObj.type = 'application/pdf';
	} else if (flieType === 'doc') {
		flieTypeObj.type = 'application/msword';
	} else if (flieType === 'docx') {
		flieTypeObj.type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
	} else if (flieType === 'xls') {
		flieTypeObj.type = 'application/vnd.ms-excel';
	} else if (flieType === 'ppt') {
		flieTypeObj.type = 'application/vnd.ms-powerpoint';
	} else if (flieType === 'pptx') {
		flieTypeObj.type = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
	}
	const blob = new Blob([fileData], flieTypeObj);
	const objectUrl = URL.createObjectURL(blob);
	const a = document.createElement('a');
	document.body.appendChild(a);
	a.setAttribute('style', 'display:none');
	a.setAttribute('href', objectUrl);
	// a.setAttribute('download', fileName || Date.parse(new Date()));
	a.setAttribute('download', fileName || (new Date()).toJSON());
	a.click();
	document.body.removeChild(a);
	// 释放URL地址
	URL.revokeObjectURL(objectUrl);
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_format_格式">format 格式</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_formatnumbertomonetization_数字货币化千分位">formatNumberToMonetization 数字货币化千分位</h3>
<div class="paragraph">
<p>默认2位小数</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">import { formatNumberToMonetization } from "fok-js";

console.log(formatNumberToMonetization(123456));
// ￥123,456.00




############### 源码 #################
/**
 * 数字货币化千分位
 */
function formatNumberToMonetization(num, decimalPlaces = 2) {

  return '￥' + formatNumberToThousand(num, decimalPlaces);
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_formatnumbertothousand_数字千分位">formatNumberToThousand 数字千分位</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">import { formatNumberToThousand } from "fok-js";

console.log(formatNumberToThousand(123456));
// 123,456.00




############### 源码 #################
import { Decimal } from '../decimal/index';

/**
 * 数字千分位
 */
function formatNumberToThousand(num, decimalPlaces = 2) {
  const parts = new Decimal(num).toFixed(decimalPlaces, Decimal.ROUND_DOWN).split('.');
  let integerPart = parts[0];
  // 在整数部分添加千分位
  integerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');

  // 如果有小数部分，则保留并拼接
  const decimalPart = parts.length &gt; 1 ? '.' + parts[1] : '';

  return integerPart + decimalPart;
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_function_函数">function 函数</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_debounce_防抖">debounce 防抖</h3>
<div class="ulist">
<ul>
<li>
<p>当事件触发时，相应的函数并不会立即触发，而是会等待一定的时间；</p>
</li>
<li>
<p>当事件密集触发时，函数的触发会被频繁的推迟；</p>
</li>
<li>
<p>只有等待了一段时间也没有事件触发，才会真正的执行响应函数。</p>
</li>
</ul>
</div>
<table class="tableblock frame-all grid-all fit-content">
<caption class="title">Table 3. 防抖参数</caption>
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名称</th>
<th class="tableblock halign-left valign-top">类型</th>
<th class="tableblock halign-left valign-top">说明</th>
<th class="tableblock halign-left valign-top">是否必传</th>
<th class="tableblock halign-left valign-top">默认值</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">function</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Function</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">需要防抖的函数</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">是</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">delay</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Number</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">延迟时间</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">否</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">200</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">immediately</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">是否立即执行</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">否</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
</tr>
</tbody>
</table>
<table class="tableblock frame-all grid-all fit-content">
<caption class="title">Table 4. 防抖返回值</caption>
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名称</th>
<th class="tableblock halign-left valign-top">类型</th>
<th class="tableblock halign-left valign-top">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">function</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Function</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">新的防抖函数</p></td>
</tr>
</tbody>
</table>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">&lt;template&gt;
  &lt;div class="page-content"&gt;
    &lt;button @click="debounceFn()"&gt;点击我&lt;/button&gt;
  &lt;/div&gt;
&lt;/template&gt;

&lt;script lang="ts"&gt;
  import { defineComponent, ref } from 'vue';
  import { debounce } from "fok-js";

  export default defineComponent({
    components: {  },
    setup() {
      //常规使用
      let debounceFn = debounce(clickTest, 1000);
      //立即执行
      // let debounceFn = debounce(clickTest, 1000, true);
      //取消执行
      // debounceFn.cancel();

      debounceFn();

      function clickTest() {
        console.log('123');
      }
      return {
        clickTest,
        debounceFn
      };
    },
  });
&lt;/script&gt;

&lt;style lang="less" scoped&gt;
  .page-content {
    padding: 16px;
  }
&lt;/style&gt;






############### 源码 #################
/**
 * @desc 函数防抖
 * 当事件触发时，相应的函数并不会立即触发，而是会等待一定的时间；
 * 当事件密集触发时，函数的触发会被频繁的推迟；
 * 只有等待了一段时间也没有事件触发，才会真正的执行响应函数。

 * @example 适用场景：
 *  频繁的点击按钮，触发某个事件
 *  输入框中频繁的输入内容

 * @param  {func} Function 要防抖的函数。
 * @param  {delay} number 需要延迟的毫秒数。
 * @param  {immediate} boolean 是否立即执行。
 * @return {Function} 新的防抖函数。
 */

function debounce(fn, delay = 200, immediate = false) {
	// 1.定义一个定时器, 保存上一次的定时器
	let timer = null
	let isInvoke = false    // 是否激活了立即执行
	// 2.真正执行的函数
	const _debounce = function(...args) {
		// 取消上一次的定时器
		if (timer) clearTimeout(timer)
		// 判断是否需要立即执行
		if (immediate &amp;&amp; !isInvoke) {
			fn.apply(this, args)
			isInvoke = true // 已经立即执行, 阻止下次触发的立即执行
		} else {
			// 延迟执行
			timer = setTimeout(() =&gt; {
				// 外部传入的真正要执行的函数
				fn.apply(this, args)
				isInvoke = false // 将isInvoke初始化
			}, delay)
		}
	}
	// 封装取消功能
	_debounce.cancel = function() {
		if (timer) clearTimeout(timer)
		timer = null
		isInvoke = false
	}
	return _debounce
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_throttle_节流">throttle 节流</h3>
<div class="ulist">
<ul>
<li>
<p>当事件触发时，相应的函数并不会立即触发，而是会等待一定的时间；</p>
</li>
<li>
<p>当事件密集触发时，函数的触发会被频繁的推迟；</p>
</li>
<li>
<p>只有等待了一段时间也没有事件触发，才会真正的执行响应函数。</p>
</li>
</ul>
</div>
<table class="tableblock frame-all grid-all fit-content">
<caption class="title">Table 5. 节流参数</caption>
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名称</th>
<th class="tableblock halign-left valign-top">类型</th>
<th class="tableblock halign-left valign-top">说明</th>
<th class="tableblock halign-left valign-top">是否必传</th>
<th class="tableblock halign-left valign-top">默认值</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">function</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Function</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">需要节流的函数</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">是</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">interval</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Number</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">间隔时间</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">否</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">200</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">options</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Object</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">节流配置</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">否</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">{ leading: true, trailing: false }</p></td>
</tr>
</tbody>
</table>
<table class="tableblock frame-all grid-all fit-content">
<caption class="title">Table 6. 节流返回值</caption>
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名称</th>
<th class="tableblock halign-left valign-top">类型</th>
<th class="tableblock halign-left valign-top">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">function</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Function</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">新的节流函数</p></td>
</tr>
</tbody>
</table>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">&lt;template&gt;
  &lt;div class="page-content"&gt;
    &lt;button @click="throttleFn()"&gt;点击我&lt;/button&gt;
  &lt;/div&gt;
&lt;/template&gt;

&lt;script lang="ts"&gt;
  import { defineComponent, ref } from 'vue';
  import { throttle } from "fok-js";

  export default defineComponent({
    components: {  },
    setup() {
      //常规使用
      let throttleFn = throttle(clickTest, 3000);
      //首次不触发和最后结束触发
      //e.g. 首次不触发leading和最后结束触发trailing: options = { leading: true, trailing: false }
      // let throttleFn = throttle(clickTest, 3000, { leading: true, trailing: false });

      throttleFn();

      function clickTest() {
        console.log('123');
      }
      return {
        clickTest,
        throttleFn
      };
    },
  });
&lt;/script&gt;

&lt;style lang="less" scoped&gt;
  .page-content {
    padding: 16px;
  }
&lt;/style&gt;




############### 源码 #################
/**
 * @desc 函数节流
 * 如果某个事件会被频繁触发，那么节流函数会按照一定的频率来执行函数；
 * 不管在这个中间有多少次触发这个事件，执行函数的频率总是固定的。

 * @example 适用场景：
 *  鼠标移动事件
 *  王者荣耀攻击键, 点击再快也是以一定攻速(频率)进行攻击

 * @param  {func} Function 要节流的函数。
 * @param  {interval} number 时间间隔。
 * @param  {options} object 选项。
 *   e.g. 首次不触发leading和最后结束触发trailing: options = { leading: true, trailing: false }
 * @return {Function} 新的节流函数。
 */

function throttle(fn, interval = 200, options = { leading: true, trailing: false }) {
  // 1.记录上一次的开始时间
  const { leading, trailing } = options
  let lastTime = 0
  let timer = null
  // 2.事件触发时, 真正执行的函数
  const _throttle = function() {
    // 2.1.获取当前事件触发时的时间
    const nowTime = new Date().getTime()
    if (!lastTime &amp;&amp; !leading) lastTime = nowTime
    // 2.2.使用当前触发的时间和之前的时间间隔以及上一次开始的时间, 计算出还剩余多长事件需要去触发函数
    const remainTime = interval - (nowTime - lastTime)
    if (remainTime &lt;= 0) {
      if (timer) {
        clearTimeout(timer)
        timer = null
      }
      // 2.3.真正触发函数
      fn()
      // 2.4.保留上次触发的时间
      lastTime = nowTime
      return
    }
    if (trailing &amp;&amp; !timer) {
      timer = setTimeout(() =&gt; {
        timer = null
        lastTime = !leading ? 0 : new Date().getTime()
        fn()
      }, remainTime)
    }
  }
  return _throttle
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_keycode">keycode</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_getkeyname_根据keycode获得键名">getKeyName 根据keycode获得键名</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getKeyName } from "fok-utils";

console.log(getKeyName(20));
//Caps Lock
console.log(getKeyName(78));
//N
console.log(getKeyName(200));
//Unknow Key(Key Code:200)



############### 源码 #################
let keyCodeMap = {
    8: 'Backspace',
    9: 'Tab',
    13: 'Enter',
    16: 'Shift',
    17: 'Ctrl',
    18: 'Alt',
    19: 'Pause',
    20: 'Caps Lock',
    27: 'Escape',
    32: 'Space',
    33: 'Page Up',
    34: 'Page Down',
    35: 'End',
    36: 'Home',
    37: 'Left',
    38: 'Up',
    39: 'Right',
    40: 'Down',
    42: 'Print Screen',
    45: 'Insert',
    46: 'Delete',

    48: '0',
    49: '1',
    50: '2',
    51: '3',
    52: '4',
    53: '5',
    54: '6',
    55: '7',
    56: '8',
    57: '9',

    65: 'A',
    66: 'B',
    67: 'C',
    68: 'D',
    69: 'E',
    70: 'F',
    71: 'G',
    72: 'H',
    73: 'I',
    74: 'J',
    75: 'K',
    76: 'L',
    77: 'M',
    78: 'N',
    79: 'O',
    80: 'P',
    81: 'Q',
    82: 'R',
    83: 'S',
    84: 'T',
    85: 'U',
    86: 'V',
    87: 'W',
    88: 'X',
    89: 'Y',
    90: 'Z',

    91: 'Windows',
    93: 'Right Click',

    96: 'Numpad 0',
    97: 'Numpad 1',
    98: 'Numpad 2',
    99: 'Numpad 3',
    100: 'Numpad 4',
    101: 'Numpad 5',
    102: 'Numpad 6',
    103: 'Numpad 7',
    104: 'Numpad 8',
    105: 'Numpad 9',
    106: 'Numpad *',
    107: 'Numpad +',
    109: 'Numpad -',
    110: 'Numpad .',
    111: 'Numpad /',

    112: 'F1',
    113: 'F2',
    114: 'F3',
    115: 'F4',
    116: 'F5',
    117: 'F6',
    118: 'F7',
    119: 'F8',
    120: 'F9',
    121: 'F10',
    122: 'F11',
    123: 'F12',

    144: 'Num Lock',
    145: 'Scroll Lock',
    182: 'My Computer',
    183: 'My Calculator',
    186: ';',
    187: '=',
    188: ',',
    189: '-',
    190: '.',
    191: '/',
    192: '`',
    219: '[',
    220: '\\',
    221: ']',
    222: '\''
};
/**
 * @desc 根据keycode获得键名
 * @param  {Number} keycode
 * @return {String}
 */
function getKeyName(keycode) {
    if (keyCodeMap[keycode]) {
        return keyCodeMap[keycode];
    } else {
        console.log('Unknow Key(Key Code:' + keycode + ')');
        return '';
    }
};</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_object_对象">object 对象</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_hasownprop_判断对象自身属性中是否具有指定的属性">hasOwnProp 判断对象自身属性中是否具有指定的属性</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { hasOwnProp } from "fok-js";

let obj = {
  a: 1,
  b: 2
};
console.log(hasOwnProp(obj, 'a'));
//true
console.log(hasOwnProp(obj, 'toString'));
//false



############### 源码 #################
/**
  * @desc   判断对象自身属性中是否具有指定的属性
  * @param {any} obj 对象
  * @param {String/Number} key 键
  * @return {Boolean}
  */
function hasOwnProp (obj, key) {
  return obj &amp;&amp; obj.hasOwnProperty ? obj.hasOwnProperty(key) : false
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_hasownval_判断对象是否包含该值">hasOwnVal 判断对象是否包含该值</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { hasOwnVal } from "fok-js";

let obj = {
  a: 1,
  b: 2
};
console.log(hasOwnVal(obj, 2));
//true
console.log(hasOwnVal(obj, '2'));
//false





############### 源码 #################
/**
  * @desc   判断对象是否包含该值,成功返回true否则false
  * @param {any} obj 对象
  * @param {any} val 值
  * @return {Boolean}
  */
function hasOwnVal (obj, val) {
  if (obj) {
    if (obj.includes) {
      return obj.includes(val)
    }
    for (let key in obj) {
      if (hasOwnProp(obj, key)) {
        if (val === obj[key]) {
          return true
        }
      }
    }
  }
  return false
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_isemptyobject_判断对象是否为空">isEmptyObject 判断对象是否为空</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { isEmptyObject } from "fok-js";

let obj = {};
let obj1 = {
  a: 1,
  b: 2
};
console.log(isEmptyObject(obj));
//true
console.log(isEmptyObject(obj1));
//false




############### 源码 #################
/**
 * @desc   判断`obj`是否为空
 * @param  {any} obj
 * @return {Boolean}
 */
function isEmptyObject(obj) {
    if (!obj || typeof obj !== 'object' || Array.isArray(obj))
        return false
    return !Object.keys(obj).length
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_pinyin_拼音">pinyin 拼音</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_topinyin_生成拼音码">toPinyin 生成拼音码</h3>
<table class="tableblock frame-all grid-all fit-content">
<caption class="title">Table 7. toPinyin对象参数属性说明</caption>
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名称</th>
<th class="tableblock halign-left valign-top">类型</th>
<th class="tableblock halign-left valign-top">说明</th>
<th class="tableblock halign-left valign-top">是否必传</th>
<th class="tableblock halign-left valign-top">默认值</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">text</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">String</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">要转换的文字</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">是</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">capital</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">首字母是否大写</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">否</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">true</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">retainNum</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">是否保留数字、英文</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">否</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">true</p></td>
</tr>
</tbody>
</table>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { toPinyin } from "fok-js";

let obj = {
  text: '测试文字asd123'
};
let obj1 = {
  text: '测试文字asd123',
  capital: false,
  retainNum: false
};
console.log(toPinyin(obj));
//CeShiWenZiasd123
console.log(toPinyin(obj1));
//ceshiwenzi</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_tofirstletters_获取字符串首字母">toFirstLetters 获取字符串首字母</h3>
<div class="listingblock">
<div class="content">
<pre>############### 源码 #################
/**
 * 获取字符串首字母
 */
const toFirstLetters =  (text) =&gt; {
  if (!text) return text;
  let arr = text.split('')
  let str = ''
  arr.forEach(item =&gt; {
    str = str + toPinyin({ text: item }).substring(0, 1)
  })
  return str
}</pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_print_打印">print 打印</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_print_打印_2">print 打印</h3>
<table class="tableblock frame-all grid-all fit-content">
<caption class="title">Table 8. 打印参数</caption>
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名称</th>
<th class="tableblock halign-left valign-top">类型</th>
<th class="tableblock halign-left valign-top">说明</th>
<th class="tableblock halign-left valign-top">是否必传</th>
<th class="tableblock halign-left valign-top">默认值</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">printArea</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">HTML</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">需要打印的HTML页面</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">是</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">printConfig</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Object</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">打印配置</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">是</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
</tbody>
</table>
<table class="tableblock frame-all grid-all fit-content">
<caption class="title">Table 9. printConfig配置项</caption>
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名称</th>
<th class="tableblock halign-left valign-top">类型</th>
<th class="tableblock halign-left valign-top">说明</th>
<th class="tableblock halign-left valign-top">是否必传</th>
<th class="tableblock halign-left valign-top">默认值</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">isPreview</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">是否预览</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">否</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>局部打印。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">&lt;template&gt;
  &lt;div ref="printArea" &gt;
	//需要打印的内容
  &lt;/div&gt;
  &lt;f-button @click="myClick"&gt;打印&lt;/f-button&gt;
&lt;/template&gt;

&lt;script setup&gt;
import { ref } from 'vue';
import { FButton } from 'fok-ui';
import { print } from 'fok-js';

const printArea = ref(); //需要打印的HTML页面
const printConfig = { //打印配置，支持扩展
	isPreview: true //是否预览
}

const myClick = () =&gt; {
	print(printArea.value, printConfig); //打印
}
&lt;/script&gt;






############### 源码 #################
function print(printHtml, printConfig) {
	  // console.log(printHtml, 'printHtml');
		let preview = printConfig.isPreview ? printConfig.isPreview : false; //是否预览

		new PrintServe({
		  ids: printHtml, // * 局部打印必传入id
		  url: '', // 打印指定的网址，这里不能跟id共存 如果共存id的优先级会比较高
		  standard: '', // 文档类型，默认是html5，可选 html5，loose，strict
		  extraHead: '', // 附加在head标签上的额外标签,使用逗号分隔
		  extraCss: '', // 额外的css连接，多个逗号分开
		  zIndex: 20002, // 预览窗口的z-index
		  previewTitle: '打印预览', // 打印预览的标题
		  previewPrintBtnLabel: '打印', // 打印预览的标题
		  popTitle: '', // title的标题
		  preview: preview, // 是否启动预览模式
		  previewBeforeOpenCallback () { // 预览窗口打开之前的callback
		    console.log('正在加载预览窗口');
		  },
		  previewOpenCallback () { // 预览窗口打开之后的callback
		    console.log('已经加载完预览窗口，预览打开了');
		  },
		  openCallback () { // 调用打印之后的回调事件
		    console.log('执行打印了');
		  },
		  closeCallback () { // 关闭打印的callback(无法区分确认or取消)
		    console.log('关闭了打印工具');
		  },
		  beforeOpenCallback () { // 开始打印之前的callback
		    console.log('开始打印之前');
		  }
		});
};</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_random_随机生成">random 随机生成</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_randomcolor_随机生成颜色">randomColor 随机生成颜色</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { randomColor } from "fok-js";

console.log(randomColor());
//#ef4923
console.log(randomColor());
//#97d1a5




############### 源码 #################
/**
 * @desc 随机生成颜色
 * @return {String}
 */
function randomColor() {
    return '#' + ('00000' + (Math.random() * 0x1000000 &lt;&lt; 0).toString(16)).slice(-6);
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_randomnum_生成指定范围的随机整数">randomNum 生成指定范围的随机整数</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { randomNum } from "fok-utils";

console.log(randomNum(1, 2));
//1
console.log(randomNum(50, 100));
//96
console.log(randomNum(100, 50));
73




############### 源码 #################
/**
 * @desc 生成指定范围[min, max]的随机数
 * @param  {Number} min
 * @param  {Number} max
 * @return {Number}
 */
function randomNum(min, max) {
    min = Math.ceil(min)
    max = Math.floor(max)
    return Math.floor(Math.random() * (max - min + 1)) + min;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_randomstr_生成指定位数的随机字符串">randomStr 生成指定位数的随机字符串</h3>
<div class="paragraph">
<p>生成的字符串包含英文字母的大小写以及数字。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { randomStr } from "fok-utils";

console.log(randomStr(8));
//2siYhXfG
console.log(randomStr(5));
//YfK4N




############### 源码 #################
/**
 * @desc 生成指定位数的随机数
 * @param  {Number} num
 * @return {Number}
 */
function randomStr(num) {
    let $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    let maxPo = $chars.length;
    let randomNum = '';
    for (let i = 0; i &lt; num; i++) {
        randomNum += $chars.charAt(Math.floor(Math.random() * maxPo));
    }

    return randomNum;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_randomcname_生成中文名字">randomCName 生成中文名字</h3>
<div class="paragraph">
<p>生成中文名字。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { randomCName } from "fok-utils";

console.log(randomCName());
// 李二</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_areatree_地区树">areaTree 地区树</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { areaTree } from "fok-utils";</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_randomarea_生成地区">randomArea 生成地区</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { randomArea } from "fok-utils";

console.log(randomArea());
// {
//     citycode: "0379",
//     adcode: "410323",
//     name: "新安县",
//     center: "112.13246,34.728909",
//     level: "district"
// }</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_randombirth_生成出生日期">randomBirth 生成出生日期</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { randomBirth } from "fok-utils";

console.log(randomBirth());
// 20120807</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_randomidcard_生成身份证">randomIdCard 生成身份证</h3>
<div class="paragraph">
<p>生成身份证
data.area 地区编码 例如：510104 成都锦江区
data.birth 出生日期 例如：19900101
data.gender 性别 1:表示男性 0:表示女性</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { randomIdCard } from "fok-utils";

console.log(randomIdCard());
// 450205201208070815

console.log(randomIdCard({ area: '530322' }));
// 530322197908217307</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_randomemail_生成邮箱地址">randomEmail 生成邮箱地址</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { randomEmail } from "fok-utils";

console.log(randomEmail());
// service888@juno.com</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_regexp_正则">regexp 正则</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_iscolor_是否为颜色值">isColor 是否为颜色值</h3>
<div class="paragraph">
<p>判断当前字符串判断是否为正确的颜色值，包含16进制颜色值、rgb或rgba。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">import { isColor } from "fok-js";

console.log(isColor('123456'));
// false
console.log(isColor('#123456'));
// true
console.log(isColor('#fff'));
// true
console.log(isColor('#FFFFFF'));
// true
console.log(isColor('#ggg'));
// false
console.log(isColor('2, 2, 2'));
// false
console.log(isColor('rgb(2, 2, 2)'));
// true
console.log(isColor('RGB(2, 2, 2)'));
// true
console.log(isColor('rgb(256, 2, 2)'));
// false
console.log(isColor('rgba(2, 2, 2, 0.5)'));
// true
console.log(isColor('RGBA(2, 2, 2, 0.5)'));
// true
console.log(isColor('rgba(2, 2, 2, 1.5)'));
// false




############### 源码 #################
/**
 * @desc 判断是否为16进制颜色，rgb 或 rgba
 * @param  {String}  str
 * @return {Boolean}
 */
function isColor(str) {
	return /^(#([0-9a-fA-F]{3}){1,2}|[rR][gG][Bb](\((\s*(2[0-4]\d|25[0-5]|[01]?\d{1,2})\s*,){2}\s*(2[0-4]\d|25[0-5]|[01]?\d{1,2})\s*\)|[Aa]\((\s*(2[0-4]\d|25[0-5]|[01]?\d{1,2})\s*,){3}\s*([01]|0\.\d+)\s*\)))$/.test(str);
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_isemail_是否为邮箱">isEmail 是否为邮箱</h3>
<div class="paragraph">
<p>判断当前字符串判断是否为正确的邮箱地址。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">import { isEmail } from "fok-js";

console.log(isEmail());
// false
console.log(isEmail('123@123'));
// false
console.log(isEmail('123cn123'));
// false
console.log(isEmail('123@123.cn'));
// true
console.log(isEmail('@vip.qq.com'));
// false
console.log(isEmail('723@yahoo.com'));
// true





############### 源码 #################
/**
 * @desc   判断是否为邮箱地址
 * @param  {String}  str
 * @return {Boolean}
 */
function isEmail(str) {
    return /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(str);
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_ishexcolor_是否为16进制颜色值">isHexColor 是否为16进制颜色值</h3>
<div class="paragraph">
<p>判断当前字符串判断是否为正确的16进制颜色值。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">import { isHexColor } from "fok-js";

console.log(isHexColor('123456'));
// false
console.log(isHexColor('#123456'));
// true
console.log(isHexColor('#fff'));
// true
console.log(isHexColor('#FFF'));
// true
console.log(isHexColor('#FFF123'));
// true
console.log(isHexColor('#FFF12G'));
// false





############### 源码 #################
/**
 * @desc   判断是否 十六进制颜色值   输入形式可为 #fff000 #f00
 * @param  {String} color   十六进制颜色值
 * @return {Boolean}
 */
function isHexColor(color) {
  const reg = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
  return reg.test(color)
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_isidcard_是否为身份证号">isIdCard 是否为身份证号</h3>
<div class="paragraph">
<p>判断当前字符串判断是否为正确的身份证号。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">import { isIdCard } from "fok-js";

console.log(isIdCard('123456'));
// 身份证号长度格式错误
console.log(isIdCard('123456789012345678'));
// 身份证号出生日期不合规
console.log(isIdCard('510824197101103465'));
//身份证号格式错误
console.log(isIdCard('510824197101107365'));
// true





############### 源码 #################
/**
 * @desc  判断是否为身份证号
 * @param  {String|Number} str
 * @return {Boolean}
 */
function isIdCard(str) {
   const val = str;
   const city = {
     11: "北京",
     12: "天津",
     13: "河北",
     14: "山西",
     15: "内蒙古",
     21: "辽宁",
     22: "吉林",
     23: "黑龙江",
     31: "上海",
     32: "江苏",
     33: "浙江",
     34: "安徽",
     35: "福建",
     36: "江西",
     37: "山东",
     41: "河南",
     42: "湖北",
     43: "湖南",
     44: "广东",
     45: "广西",
     46: "海南",
     50: "重庆",
     51: "四川",
     52: "贵州",
     53: "云南",
     54: "西藏",
     61: "陕西",
     62: "甘肃",
     63: "青海",
     64: "宁夏",
     65: "新疆",
     71: "台湾",
     81: "香港",
     82: "澳门",
     91: "国外"
   };
   // 长度校验 15位号码应全为数字 18位号码末位可以为数字或X
   if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(val))) {
     return val === null || val === "" ? null : "身份证号长度格式错误";
   }
   // 地址校验
   if (!city[val.substr(0, 2)]) {
     return val === null || val === "" ? null : "身份证号地址编码错误";
   }
   // 位校验
   if (val.length === 18) {
     const arrData = val.match(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X|x)$/);
     const {
       year,
       month,
       day
     } = {
         year: arrData[2],
         month: arrData[3],
         day: arrData[4]
       };
     const birthday = new Date(year + "/" + month + "/" + day);
     const now = new Date();
     const nowYear = now.getFullYear();
     const bGoodDay = (birthday.getFullYear() === Number(year)) &amp;&amp; ((birthday.getMonth() + 1) === Number(
       month)) &amp;&amp; (birthday.getDate() === Number(day));
     // 年月日是否合理
     if (!bGoodDay) {
       return val === null || val === "" ? null : "身份证号出生日期不合规";
     } else {
       // 判断年份的范围（0岁到100岁之间)
       const time = Number(nowYear) - Number(year);
       if (!(time &gt;= 0 &amp;&amp; time &lt;= 100)) {
         return val === null || val === "" ? null : "身份证号出生日期不合规";
       }
     }

     const list = val.split("");
     // 加权因子
     const factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
     // 校验位
     const parity = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
     let {
       sum,
       ai,
       wi
     } = {
         sum: 0,
         ai: 0,
         wi: 0
       };
     for (let i = 0; i &lt; 17; i++) {
       ai = list[i];
       wi = factor[i];
       sum += ai * wi;
     }
     if (parity[sum % 11] !== list[17]) {
       return val === null || val === "" ? null : "身份证号格式错误";
     }
   }

	 return true;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_isip_判断是否为ip地址">isIp 判断是否为ip地址</h3>
<div class="paragraph">
<p>判断是否为ip地址。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">import { isIp } from "fok-js";

console.log(isIp('123456'));
// false
console.log(isIp('http://www'));
// false
console.log(isIp('172.168.0.1'));
// true
console.log(isIp('1.1.1.1'));
// true




############### 源码 #################
/**
 * @desc   判断是否为ip地址
 * @param  {String} str
 * @return {Boolean}
 */
function isIp(str) {
    return /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(str);
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_isphoneno_判断是否为手机号">isPhoneNo 判断是否为手机号</h3>
<div class="paragraph">
<p>判断是否为手机号。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">import { isPhoneNo } from "fok-js";

console.log(isPhoneNo('123456'));
// false
console.log(isPhoneNo('12333333333'));
// false
console.log(isPhoneNo('010-1234567'));
// false
console.log(isPhoneNo('15555555555'));
// true




############### 源码 #################
/**
 * @desc   判断是否为手机号
 * @param  {String|Number} str
 * @return {Boolean}
 */
function isPhoneNo(str) {
    return /^(0|86|17951)?(13[0-9]|15[012356789]|16[6]|19[89]]|17[01345678]|18[0-9]|14[579])[0-9]{8}$/.test(str)
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_ispositiveinteger_判断是否为正整数">isPositiveInteger 判断是否为正整数</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">import { isPositiveInteger } from "fok-js";

console.log(isPositiveInteger(-5));
// false
console.log(isPositiveInteger(0));
// false
console.log(isPositiveInteger('q'));
// false
console.log(isPositiveInteger('1q'));
// false
console.log(isPositiveInteger(10));
// true
console.log(isPositiveInteger('10'));
// true




############### 源码 #################
/**
 * @desc   判断是否正整数
 * @param  {String} str
 * @return {Boolean}
 */
function isPositiveInteger(str) {
		let pattern = /^[1-9]\d*$/;
		return pattern.test(str);
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_istelephoneno_判断是否为座机号">istelephoneNo 判断是否为座机号</h3>
<div class="paragraph">
<p>判断是否为座机号。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">import { istelephoneNo } from "fok-js";

console.log(istelephoneNo('123456'));
// false
console.log(istelephoneNo('15555555555'));
// true
console.log(istelephoneNo('010-1234567'));
// true




############### 源码 #################
/**
 * @desc   判断是否为座机号
 * @param  {String|Number} str
 * @return {Boolean}
 */
function istelephoneNo(str) {
    return /^((0\d{2,3}-\d{7,8})|(1[3456789]\d{9}))$/.test(str)
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_isurl_判断是否为url地址">isUrl 判断是否为URL地址</h3>
<div class="paragraph">
<p>判断是否为URL地址。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-vue" data-lang="vue">import { isUrl } from "fok-js";

console.log(isUrl('123456'));
// false
console.log(isUrl('http://www'));
// false
console.log(isUrl('172.168.0.1'));
// false
console.log(isUrl('http://172.168.0.1'));
// false
console.log(isUrl('http://www.sdfde.cn'));
// true
console.log(isUrl('http://localhost:5003/#/login'));
// false




############### 源码 #################
/**
 * @desc   判断是否为URL地址
 * @param  {String} str
 * @return {Boolean}
 */
function isUrl(str) {
    return /[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&amp;//=]*)/i.test(str);
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_storage_缓存">storage 缓存</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_getlocal_获取localstorage值">getLocal 获取localstorage值</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { Storage } from 'fok-js';

Storage.getLocal('his_menu_open_url')</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_setlocal_设置localstorage值">setLocal 设置localstorage值</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { Storage } from 'fok-js';

Storage.setLocal('his_menu_open_url', 'xxx');</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_getsession_获取sessionstorage值">getSession 获取sessionstorage值</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { Storage } from 'fok-js';

Storage.getSession('his_menu_nav');</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_setsession_设置sessionstorage值">setSession 设置sessionstorage值</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { Storage } from 'fok-js';

Storage.setSession('his_menu_nav', 'xxx');</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_removelocal_删除localstorage值">removeLocal 删除localstorage值</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { Storage } from 'fok-js';

Storage.removeLocal('his_menu_open_url');</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_removesession_删除sessionstorage值">removeSession 删除sessionstorage值</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { Storage } from 'fok-js';

Storage.removeSession('his_menu_nav');</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_clearlocal_删除全部localstorage值">clearLocal 删除全部localstorage值</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { Storage } from 'fok-js';

Storage.clearLocal();</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_clearsession_删除全部sessionstorage值">clearSession 删除全部sessionstorage值</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { Storage } from 'fok-js';

Storage.clearSession();</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_clearall_删除全部localstorage和sessionstorage值">clearAll 删除全部localstorage和sessionstorage值</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { Storage } from 'fok-js';

Storage.clearAll();</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_string_字符串">string 字符串</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_camelcase_转驼峰">camelCase 转驼峰</h3>
<div class="paragraph">
<p>转换字符串string为驼峰写法。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { camelCase } from "fok-js";

console.log(camelCase('Foo Bar'));
// 'fooBar'
console.log(camelCase('--foo-bar--'));
// 'fooBar'
console.log(camelCase('__FOO_BAR__'));
// 'fooBar'





############### 源码 #################
/**
 * @desc    转换字符串string为驼峰写法。
 * @param   {[string='']} string 要转换的字符串
 * @return  {String} 返回驼峰写法的字符串
 */

const camelCase = (string) =&gt;
	words(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) =&gt; {
		word = word.toLowerCase();
		return result + (index ? upperFirst(word) : word);
	}, '');</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_deduplication_字符串去重">deduplication 字符串去重</h3>
<div class="paragraph">
<p>去除字符串中的重复字符，并返回一个新的字符串。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { deduplication } from "fok-js";

let str = '123addf2..@@';
console.log(deduplication(str));
//123adf.@




############### 源码 #################
/**
 * @desc    字符串去除重复字符
 * @param   {String} string 要去重的字符串
 * @return  {String} 一个新字符串
 */
function deduplication(myStr) {
	return [...new Set(myStr)].join('');
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_digituppercase_金额小写转大写">digitUppercase 金额小写转大写</h3>
<div class="paragraph">
<p>转换字符串string为snake case。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { digitUppercase } from "fok-js";

console.log(digitUppercase(11.25));
// 壹拾壹元贰角伍分





############### 源码 #################
/**
 * @desc   金额小写转大写
 * @param  {Number} n
 * @return {String}
 */
function digitUppercase(money) {
	// 汉字的数字
	let cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
	// 基本单位
	let cnIntRadice = new Array('', '拾', '佰', '仟');
	// 对应整数部分扩展单位
	let cnIntUnits = new Array('', '万', '亿', '兆');
	// 对应小数部分单位
	let cnDecUnits = new Array('角', '分', '毫', '厘');
	// 整数金额时后面跟的字符
	let cnInteger = '整';
	// 整型完以后的单位
	let cnIntLast = '元';
	// 最大处理的数字
	let maxNum = 999999999999999.9999;
	// 金额整数部分
	let integerNum;
	// 金额小数部分
	let decimalNum;
	// 输出的中文金额字符串
	let chineseStr = '';
	// 分离金额后用的数组，预定义
	let parts;
	if (money == '') {
		return '';
	}
	money = parseFloat(money);
	if (money &gt;= maxNum) {
		// 超出最大处理数字
		return '';
	}
	if (money == 0) {
		chineseStr = cnNums[0] + cnIntLast + cnInteger;
		return chineseStr;
	}
	// 转换为字符串
	money = money.toString();
	if (money.indexOf('.') == -1) {
		integerNum = money;
		decimalNum = '';
	} else {
		parts = money.split('.');
		integerNum = parts[0];
		decimalNum = parts[1].substr(0, 4);
	}
	// 获取整型部分转换
	if (parseInt(integerNum, 10) &gt; 0) {
		let zeroCount = 0;
		let IntLen = integerNum.length;
		for (let i = 0; i &lt; IntLen; i++) {
			let n = integerNum.substr(i, 1);
			let p = IntLen - i - 1;
			let q = p / 4;
			let m = p % 4;
			if (n == '0') {
				zeroCount++;
			} else {
				if (zeroCount &gt; 0) {
					chineseStr += cnNums[0];
				}
				// 归零
				zeroCount = 0;
				chineseStr += cnNums[parseInt(n)] +
					cnIntRadice[m];
			}
			if (m == 0 &amp;&amp; zeroCount &lt; 4) {
				chineseStr += cnIntUnits[q];
			}
		}
		chineseStr += cnIntLast;
	}
	// 小数部分
	if (decimalNum != '') {
		let decLen = decimalNum.length;
		for (let i = 0; i &lt; decLen; i++) {
			let n = decimalNum.substr(i, 1);
			if (n != '0') {
				chineseStr += cnNums[Number(n)] + cnDecUnits[i];
			}
		}
	}
	if (chineseStr == '') {
		chineseStr += cnNums[0] + cnIntLast + cnInteger;
	} else if (decimalNum == '') {
		chineseStr += cnInteger;
	}
	return chineseStr;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_ishasillegalchar_检测是否包含非法字符">isHasIllegalChar 检测是否包含非法字符</h3>
<div class="paragraph">
<p>检测是否包含非法字符，返回一个描述对象。
匹配不区分大小写，进行完全匹配，支持多行匹配。
返回对象的subStringResult表示对整个subString的检测结果，contains表示是否包含，count是出现次数，positions表示出现的位置。
overallResult数组是对subString中单个字符的的检测结果，数组元素为对象，character表示当前检测字符，contains表示是否包含，count是出现次数，positions表示出现的位置。
isHasIllegalChar方法还支持第三个参数type，默认值是&#8217;str'，表示subString为字符串。可选值是&#8217;reg'，表示subString为正则表达式，如果'[a-z]'。如果type为&#8217;reg&#8217;时，subString为错误的正则表达式，则直接返回匹配结果，结果为没有。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { isHasIllegalChar } from "fok-js";

let mainString = "这是一个aer示例字\n符串，包含要123检查的,./内容。要检\n查的内@#$容可3245能会出现ASD多次。";
let subString = "aer示例x,d";
// 使用字符串匹配
let resultStr = isHasIllegalChar(mainString, subString);
console.log(resultStr);





############### 源码 #################
/**
 * 检测是否包含非法字符
 * @param {*} mainString 原始字符串
 * @param {*} subString 非法字符串 | 正则字符串
 * @param {*} type str | reg
 * @returns
 */
function isHasIllegalChar(mainString, subString, type = 'str') {
    let escapedSubString;
    if (type === 'reg') {
        try {
            new RegExp(subString);  // 检查是否是合法的正则表达式
            escapedSubString = subString;
        } catch (error) {
            return { error: 'Invalid regular expression string.' };
        }
    } else {
        escapedSubString = escapeRegExp(subString);
    }
		// 构建全匹配的正则表达式 i不区分大小写 g匹配多个实例 m匹配多行字符串
    let pattern = new RegExp(`\\b${escapedSubString}\\b`, 'gim');
    let result = [];
    // 统计每个字符的信息
    if (type === 'reg') {
        let charPattern = new RegExp(escapedSubString, 'gim');
        let match;
        while ((match = charPattern.exec(mainString)) !== null) {
            let char = match[0];
            let charResult = {
                character: char,
                count: 1,
                positions: [match.index],
                contains: true
            };
            result.push(charResult);
        }
    } else {
        for (let i = 0; i &lt; subString.length; i++) {
            let char = subString[i];
            let charResult = {
                character: char,
                count: 0,
                positions: [],
                contains: false
            };
            let charIndex = mainString.indexOf(char);
            while (charIndex !== -1) {
                charResult.count++;
                charResult.positions.push(charIndex);
                charResult.contains = true;
                charIndex = mainString.indexOf(char, charIndex + 1);
            }
            result.push(charResult);
        }
    }
    // 针对 subString 的检测结果
    let subStringResult = {
        positions: [],
        count: 0,
        contains: false
    };
    let subStringIndex = mainString.indexOf(subString);
    while (subStringIndex !== -1) {
        subStringResult.count++;
        subStringResult.positions.push(subStringIndex);
        subStringIndex = mainString.indexOf(subString, subStringIndex + 1);
    }
    subStringResult.contains = subStringResult.count &gt; 0;
    return {
        overallResult: result,
        subStringResult: subStringResult
    };
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_kebabcase_转烤肉串">kebabCase 转烤肉串</h3>
<div class="paragraph">
<p>转换字符串string为kebab case。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { kebabCase } from "fok-js";

console.log(kebabCase('Foo Bar'));
// 'foo-bar'
console.log(kebabCase('fooBar'));
// 'foo-bar'
console.log(kebabCase('__FOO_BAR__'));
// 'foo-bar'




############### 源码 #################
/**
 * @desc    转换字符串string为kebab case。
 * @param   {[string='']} string 要转换的字符串
 * @return  {String} 返回烤肉串写法的字符串
 */
const kebabCase = (string) =&gt;
	words(toString(string).replace(/['\u2019]/g, '')).reduce(
		(result, word, index) =&gt; result + (index ? '-' : '') + word.toLowerCase(),
		'',
	);</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_snakecase_转下划线">snakeCase 转下划线</h3>
<div class="paragraph">
<p>转换字符串string为snake case。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { snakeCase } from "fok-js";

console.log(snakeCase('Foo Bar'));
// 'foo_bar'
console.log(snakeCase('fooBar'));
// 'foo_bar'
console.log(snakeCase('--FOO-BAR--'));
// 'foo_bar'




############### 源码 #################
/**
 * @desc    转换字符串string为snake case。
 * @param   {[string='']} string 要转换的字符串
 * @return  {String} 返回下划线写法的字符串
 */
const snakeCase = (string) =&gt;
	words(toString(string).replace(/['\u2019]/g, '')).reduce(
		(result, word, index) =&gt; result + (index ? '_' : '') + word.toLowerCase(),
		'',
	);</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_upperfirst_转首字母大写">upperFirst 转首字母大写</h3>
<div class="paragraph">
<p>转换字符串string为snake case。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { upperFirst } from "fok-js";

console.log(upperFirst('fred'));
// 'Fred'
console.log(upperFirst('FRED'));
// 'FRED'
console.log(upperFirst('foo bar'));
// 'Foo bar'</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_support">support</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_issupportwebp_判断浏览器是否支持webp格式图片">isSupportWebP 判断浏览器是否支持webP格式图片</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { isSupportWebP } from "fok-utils";

console.log(isSupportWebP());
//true




############### 源码 #################
/**
 * @desc 判断浏览器是否支持webP格式图片
 * @return {Boolean}
 */
function isSupportWebP() {
    return !![].map &amp;&amp; document.createElement('canvas').toDataURL('image/webp').indexOf('data:image/webp') == 0;
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_time_时间">time 时间</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_获取时间实例">获取时间实例</h3>
<div class="paragraph">
<p>直接使用dayjs()方法，等同于 dayjs(new Date()) 的调用。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

console.log(dayjs());
// Dayjs2类型对象</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_获取毫秒">获取毫秒</h3>
<div class="paragraph">
<p>值为0到999。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

console.log(dayjs().millisecond());
// 995</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_获取秒">获取秒</h3>
<div class="paragraph">
<p>值为0到59。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

console.log(dayjs().second());
// 6</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_获取分钟">获取分钟</h3>
<div class="paragraph">
<p>值为0到59。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

console.log(dayjs().minute());
// 32</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_获取小时">获取小时</h3>
<div class="paragraph">
<p>值为0到23。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

console.log(dayjs().hour());
// 11</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_获取日期">获取日期</h3>
<div class="paragraph">
<p>值为1到31。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

console.log(dayjs().date());
// 23</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_获取星期">获取星期</h3>
<div class="paragraph">
<p>值为0(星期天)到6(星期六)。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

console.log(dayjs().day());
// 1</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_获取月">获取月</h3>
<div class="paragraph">
<p>值为0到11。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

console.log(dayjs().month());
// 9</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_获取年">获取年</h3>
<div class="paragraph">
<p>值为0到11。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

console.log(dayjs().year());
// 2023</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_设置时间">设置时间</h3>
<div class="paragraph">
<p>同获取各种时间方法，区别是需要传入参数值。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

console.log(dayjs().year(2000));
// 设置年</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_时间相加">时间相加</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

console.log(dayjs().add(7, 'day'));
// Dayjs2时间对象</code></pre>
</div>
</div>
<div class="paragraph">
<p>各个传入的单位对大小写不敏感，支持缩写和复数。 请注意，缩写是区分大小写的。</p>
</div>
<table class="tableblock frame-all grid-all fit-content">
<caption class="title">Table 10. 支持的单位列表</caption>
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">单位</th>
<th class="tableblock halign-left valign-top">缩写</th>
<th class="tableblock halign-left valign-top">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">day</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">d</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">日</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">week</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">w</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">周</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">month</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">M</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">月份(0-11)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">year</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">y</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">年</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">hour</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">h</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">小时</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">minute</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">m</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">分钟</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">second</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">s</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">秒</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">millisecond</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ms</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">毫秒</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect2">
<h3 id="_时间相减">时间相减</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

console.log(dayjs().subtract(7, 'day'));
// Dayjs2时间对象</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_时间加减链式调用">时间加减链式调用</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

console.log(dayjs('2019-01-25').add(1, 'day').subtract(1, 'year').year(2009).toString());
// Sun, 25 Jan 2009 16:00:00 GMT</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_格式化">格式化</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

// 默认返回的是 ISO8601 格式字符串
console.log(dayjs().format());
// 2023-10-23T11:55:27+08:00
console.log(dayjs('2019-01-25').format('DD/MM/YYYY'))
// 25/01/2019
console.log(dayjs().format('YYYY-MM-DD HH:mm:ss')) //24小时制
// 2023-10-23 13:33:34
console.log(dayjs().format('YYYY-MM-DD hh:mm:ss')) //12小时制
// 2023-10-23 01:34:03</code></pre>
</div>
</div>
<table class="tableblock frame-all grid-all fit-content">
<caption class="title">Table 11. 支持的格式化占位符列表</caption>
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">标识</th>
<th class="tableblock halign-left valign-top">示例</th>
<th class="tableblock halign-left valign-top">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">YY</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">18</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">年，两位数</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">YYYY</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2018</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">年，四位数</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">M</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1-12</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">月,从1开始</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">MM</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">01-12</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">月，两位数</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">MMM</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Jan-Dec</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">月，英文缩写</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">D</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1-31</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">日</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">DD</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">01-31</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">日，两位数</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">d</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0-6</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">一周中的一天，星期天是 0</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">dd</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Su-Sa</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">最简写的星期几</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">ddd</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Sun-Sat</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">简写的星期几</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">dddd</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Sunday-Saturday</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">星期几，英文全称</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">H</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0-23</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">小时，24小时制,一位数</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">HH</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">00-23</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">小时，24小时制,两位数</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">h</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1-12</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">小时, 12小时制,一位数</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">hh</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">01-12</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">小时, 12小时制,两位数</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">m</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0-59</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">分钟</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">mm</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">00-59</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">分钟，两位数</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">s</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0-59</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">秒</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">ss</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">00-59</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">秒，两位数</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">S</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0-9</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">毫秒(十),一位数</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">SS</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">00-99</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">毫秒(百),两位数</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">SSS</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">000-999</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">毫秒,三位数</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Z</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-05:00</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">UTC 的偏移量，±HH:mm</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">ZZ</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-0500</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">UTC 的偏移量，±HHmm</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">A</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">AM / PM</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">上/下午,大写</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">a</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">am / pm</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">上/下午,小写</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Do</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1st&#8230;&#8203; 31st</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">月份的日期与序号</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect2">
<h3 id="_判断是否为闰年">判断是否为闰年</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { dayjs } from "fok-js";

console.log(dayjs('2001-01-01').isLeapYear());
//false
console.log(dayjs('2000-01-01').isLeapYear());
//true</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_formatpasstime_格式化距现在的已过时间">formatPassTime 格式化距现在的已过时间</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { formatPassTime } from "fok-js";

console.log(formatPassTime(new Date('2013-10-02')));
//10年前
console.log(formatPassTime(new Date('2023-10-02')));
//3个月前
console.log(formatPassTime(new Date('2033-10-02')));
//-9年前




############### 源码 #################
/**
 * @desc   格式化${startTime}距现在的已过时间
 * @param  {Date} startTime
 * @return {String}
 */
function formatPassTime(startTime) {
    let currentTime = Date.parse(new Date()),
        time = currentTime - startTime,
        day = parseInt(time / (1000 * 60 * 60 * 24)),
        hour = parseInt(time / (1000 * 60 * 60)),
        min = parseInt(time / (1000 * 60)),
        month = parseInt(day / 30),
        year = parseInt(month / 12);
    if (year) return year + "年前"
    if (month) return month + "个月前"
    if (day) return day + "天前"
    if (hour) return hour + "小时前"
    if (min) return min + "分钟前"
    else return '刚刚'
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_formatremaintime_格式化现在距指定时间的剩余时间">formatRemainTime 格式化现在距指定时间的剩余时间</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { formatRemainTime } from "fok-js";

console.log(formatRemainTime(new Date('2025-10-02 12:12:12')));
//636天 21小时 43分钟 46秒
console.log(formatRemainTime(new Date('2023-10-02')));
//0天 0小时 0分钟 0秒
console.log(formatRemainTime(new Date('2033-10-02')));
//3558天 17小时 33分钟 42秒




############### 源码 #################
/**
 * @desc   格式化现在距${endTime}的剩余时间
 * @param  {Date} endTime
 * @return {String}
 */
function formatRemainTime(endTime) {
    let startDate = new Date(); //开始时间
    let endDate = new Date(endTime); //结束时间
    let t = endDate.getTime() - startDate.getTime(); //时间差
    let d = 0,
        h = 0,
        m = 0,
        s = 0;
    if (t &gt;= 0) {
        d = Math.floor(t / 1000 / 3600 / 24);
        h = Math.floor(t / 1000 / 60 / 60 % 24);
        m = Math.floor(t / 1000 / 60 % 60);
        s = Math.floor(t / 1000 % 60);
    }
    return d + "天 " + h + "小时 " + m + "分钟 " + s + "秒";
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_formattimestamp_时间戳格式化">formatTimeStamp 时间戳格式化</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { formatTimeStamp } from "fok-js";

console.log(formatTimeStamp(Date.now()));
//2024-01-04 14:48:38
console.log(formatTimeStamp(new Date().getTime()));
//2024-01-04 14:49:33
console.log(formatTimeStamp(new Date().valueOf()));
//2024-01-04 14:50:26




############### 源码 #################
/**
 * @desc 时间戳转年月日时分秒
 * @param {Number} date
 * @returns {String}   年-月-日 时:分:秒
 */
function formatTimeStamp(value) {
	if (value) {
		//将时间戳格式转换成年月日时分秒
		let date = new Date(value);
		let Y = date.getFullYear() + '-';
		let M = (date.getMonth() + 1 &lt; 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
		let D = (date.getDate() &lt; 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';

		let h = (date.getHours() &lt; 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
		let m = (date.getMinutes() &lt; 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
		let s = (date.getSeconds() &lt; 10 ? '0' + (date.getSeconds()) : date.getSeconds());
		return Y + M + D + h + m + s;
	} else {
		return ''
	}
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_getafterdays_获取某天之后的几天">getAfterDays 获取某天之后的几天</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getAfterDays } from "fok-js";

console.log(getAfterDays('2023-12-31', 5));
//['2023-12-31', '2024-01-01', '2024-01-02', '2024-01-03', '2024-01-04']





############### 源码 #################
/**
 * @desc 获取某天之后的几天
 * @param { String } 计算时间
 * @param { Number } 后几天
 * @returns [days] 之后的几天
 */
function getAfterDays(startTime, dayNo) {
    if (!isPositiveInteger(dayNo)) {
			console.log('传入的时间天数不合法，必须为正整数');
			return;
		}
		let dayArr = [];
		for (let i = 0; i &lt; Number(dayNo); i++) {
			dayArr.push(dayjs(dayjs(startTime).add(i, 'day')).format("YYYY-MM-DD"));
		}
    return dayArr;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_getbeforedays_获取某天之前的几天">getBeforeDays 获取某天之前的几天</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getBeforeDays } from "fok-js";

console.log(getBeforeDays('2024-01-01', 5));
//['2023-12-28', '2023-12-29', '2023-12-30', '2023-12-31', '2024-01-01']





############### 源码 #################
/**
 * @desc 获取某天之前的几天
 * @param { String } 计算时间
 * @param { Number } 前几天
 * @returns [days] 之前的几天
 */

function getBeforeDays(startTime, dayNo) {
    if (!isPositiveInteger(dayNo)) {
			console.log('传入的时间天数不合法，必须为正整数');
			return;
		}
		let dayArr = [];
		for (let i = 0; i &lt; Number(dayNo); i++) {
			dayArr.push(dayjs(dayjs(startTime).subtract(i, 'day')).format("YYYY-MM-DD"));
		}
    return dayArr.reverse();
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_getlastweek_获取上周">getLastWeek 获取上周</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getLastWeek } from "fok-js";

console.log(getLastWeek());
//['2024-01-08', '2024-01-09', '2024-01-10', '2024-01-11', '2024-01-12', '2024-01-13', '2024-01-14']





############### 源码 #################
/**
 * @desc 获取上周
 * @returns [days] 上周几天
 */
function getLastWeek() {
    let weekArr = [dayjs().weekday(-7).format("YYYY-MM-DD"), dayjs().weekday(-6).format("YYYY-MM-DD"), dayjs().weekday(-5).format("YYYY-MM-DD"), dayjs().weekday(-4).format("YYYY-MM-DD"), dayjs().weekday(-3).format("YYYY-MM-DD"), dayjs().weekday(-2).format("YYYY-MM-DD"), dayjs().weekday(-1).format("YYYY-MM-DD")];
    return weekArr;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_getnextweek_获取下周">getNextWeek 获取下周</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getNextWeek } from "fok-js";

console.log(getNextWeek());
//['2024-01-22', '2024-01-23', '2024-01-24', '2024-01-25', '2024-01-26', '2024-01-27', '2024-01-28']




############### 源码 #################
/**
 * @desc 获取下周
 * @returns [days] 下周几天
 */
function getNextWeek() {
    let weekArr = [dayjs().weekday(7).format("YYYY-MM-DD"), dayjs().weekday(8).format("YYYY-MM-DD"), dayjs().weekday(9).format("YYYY-MM-DD"), dayjs().weekday(10).format("YYYY-MM-DD"), dayjs().weekday(11).format("YYYY-MM-DD"), dayjs().weekday(12).format("YYYY-MM-DD"), dayjs().weekday(13).format("YYYY-MM-DD")];
    return weekArr;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_getthisweek_获取本周">getThisWeek 获取本周</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getThisWeek } from "fok-js";

console.log(getThisWeek());
//['2024-01-15', '2024-01-16', '2024-01-17', '2024-01-18', '2024-01-19', '2024-01-20', '2024-01-21']




############### 源码 #################
/**
 * @desc 获取本周
 * @returns [days] 本周几天
 */
function getThisWeek() {
    let weekArr = [dayjs().weekday(0).format("YYYY-MM-DD"), dayjs().weekday(1).format("YYYY-MM-DD"), dayjs().weekday(2).format("YYYY-MM-DD"), dayjs().weekday(3).format("YYYY-MM-DD"), dayjs().weekday(4).format("YYYY-MM-DD"), dayjs().weekday(5).format("YYYY-MM-DD"), dayjs().weekday(6).format("YYYY-MM-DD")];
    return weekArr;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_monthdays_获取指定月份的天数">monthDays 获取指定月份的天数</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { monthDays } from "fok-js";

console.log(monthDays('2001-11-01'));
//30
console.log(monthDays('2023-01-01'));
//31




############### 源码 #################
/**
 * @desc 获取指定日期月份的总天数
 * @param {Date} time
 * @return {Number}
*/
function monthDays(time){
    time = new Date(time);
    let year = time.getFullYear();
    let month = time.getMonth() + 1;
    return new Date(year, month, 0).getDate();
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_timeleft_计算剩余时间">timeLeft 计算剩余时间</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { timeLeft } from "fok-js";

console.log(timeLeft('2023-01-01 01:02:03', '2024-05-05 04:05:06'));
//{d: 490, h: 3, m: 3, s: 3}
console.log(timeLeft('2024-05-05 01:02:03', '2023-01-01 04:05:06'));
//{d: 0, h: 0, m: 0, s: 0}




############### 源码 #################
/**
 * @desc ${startTime - endTime}的剩余时间,startTime大于endTime时，均返回0
 * @param { Date | String } startTime
 * @param { Date | String } endTime
 * @returns { any } { d, h, m, s } 天 时 分 秒
 */
function timeLeft(startTime, endTime) {
    if (!startTime || !endTime) {
        return
    }
    let startDate,endDate;
    if (startTime instanceof Date) {
        startDate = startTime;
    } else {
        startDate = new Date(startTime.replace(/-/g, '/')) //开始时间
    }
    if (endTime instanceof Date) {
    	endDate = endTime;
    } else {
        endDate = new Date(endTime.replace(/-/g, '/')) //结束时间
    }
    let t = endDate.getTime() - startDate.getTime()
    let d = 0,
        h = 0,
        m = 0,
        s = 0
    if (t &gt;= 0) {
        d = Math.floor(t / 1000 / 3600 / 24)
        h = Math.floor(t / 1000 / 60 / 60 % 24)
        m = Math.floor(t / 1000 / 60 % 60)
        s = Math.floor(t / 1000 % 60)
    }
    return { d, h, m, s }
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_tools_工具">tools 工具</h2>
<div class="sectionbody">
<div class="sect3">
<h4 id="_clone_浅拷贝">clone 浅拷贝</h4>
<div class="paragraph">
<p>这个方法参考自structured clone algorithm 以及支持 arrays、array buffers、 booleans、 date objects、maps、 numbers， Object 对象, regexes, sets, strings, symbols, 以及 typed arrays。 arguments对象的可枚举属性会拷贝为普通对象。 一些不可拷贝的对象，例如error objects、functions, DOM nodes, 以及 WeakMaps 会返回空对象。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { clone } from "fok-js";

let objects = [{ 'a': 1 }, { 'b': 2 }];
let shallow = clone(objects);
console.log(shallow[0] === objects[0]);
//true</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_clonedeep_深拷贝">cloneDeep 深拷贝</h4>
<div class="paragraph">
<p>这个方法参考自structured clone algorithm 以及支持 arrays、array buffers、 booleans、 date objects、maps、 numbers， Object 对象, regexes, sets, strings, symbols, 以及 typed arrays。 arguments对象的可枚举属性会拷贝为普通对象。 一些不可拷贝的对象，例如error objects、functions, DOM nodes, 以及 WeakMaps 会返回空对象。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { cloneDeep } from "fok-js";

let objects = [{ 'a': 1 }, { 'b': 2 }];
let deep = cloneDeep(objects);
console.log(deep[0] === objects[0]);
//false





############### 源码 #################
/**
 *
 * @desc 创建一个 value 的深拷贝。
 * @param {value(*)}  要拷贝的值
 * @return {(*)} 拷贝后的值
 */
function cloneDeep(obj) {
	if (obj === null || typeof obj !== 'object' || obj instanceof Dayjs) {
		return obj;
	}

	if (Array.isArray(obj)) {
		let copy = [];
		for (let i = 0; i &lt; obj.length; i++) {
			copy[i] = cloneDeep(obj[i]);
		}
		return copy;
	}

	if (typeof obj === 'object') {
		let copy = {};
		for (let key in obj) {
			if (obj.hasOwnProperty(key)) {
				copy[key] = cloneDeep(obj[key]);
			}
		}
		return copy;
	}
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_eq_是否相等">eq 是否相等</h4>
<div class="paragraph">
<p>执行SameValueZero 比较两者的值，来确定它们是否相等。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { eq } from "fok-js";

let object = { 'a': 1 };
let other = { 'a': 1 };
console.log(eq(object, object));
//true
console.log(eq(object, other));
//false
console.log(eq('a', Object('a')));
//false
console.log(eq(NaN, NaN));
//true




############### 源码 #################
/**
 * @desc 执行SameValueZero 比较两者的值，来确定它们是否相等。
 * @param {value(*)}  要比较的值
 * @param {other (*)} 另一个要比较的值
 * @return boolean 如果两个值相等返回 true ，否则返回 false
 */

function eq(value, other) {
    return value === other || (value !== value &amp;&amp; other !== other);
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_getagebyidcard_根据身份证号返回年龄">getAgeByIDcard 根据身份证号返回年龄</h4>
<div class="paragraph">
<p>从身份证号中返回年龄数据。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getAgeByIDcard } from "fok-js";

console.log(getAgeByIDcard('123456789012345678'));
//身份证号出生日期不合规
console.log(getAgeByIDcard('510824197101103465'));
//身份证号格式错误
console.log(getAgeByIDcard('510824197101107365'));
//52





############### 源码 #################
/**
 *
 * @desc 根据身份证号返回年龄。
 * @param  {val} string 身份证号。
 * @return number 年龄
 */
function getAgeByIDcard(identityCard) {
	let len = (identityCard + "").length;
	let result = isIdCard(identityCard);
	if(result === true) {
		let strBirthday = "";
		if (len == 18)//处理18位的身份证号码从号码中得到生日和性别代码
		{
		    strBirthday = identityCard.substr(6, 4) + "/" + identityCard.substr(10, 2) + "/" + identityCard.substr(12, 2);
		}
		if (len == 15) {
		    strBirthday = "19" + identityCard.substr(6, 2) + "/" + identityCard.substr(8, 2) + "/" + identityCard.substr(10, 2);
		}
		//时间字符串里，必须是“/”
		let birthDate = new Date(strBirthday);
		let nowDateTime = new Date();
		let age = nowDateTime.getFullYear() - birthDate.getFullYear();
		//再考虑月、天的因素;.getMonth()获取的是从0开始的，这里进行比较，不需要加1
		if (nowDateTime.getMonth() &lt; birthDate.getMonth() || (nowDateTime.getMonth() == birthDate.getMonth() &amp;&amp; nowDateTime.getDate() &lt; birthDate.getDate())) {
		    age--;
		}
		return age;
	}
	else {
		return result;
	}
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_getbirthdaybyidcard_根据身份证号返回出生日期">getBirthdayByIDcard 根据身份证号返回出生日期</h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getBirthdayByIDcard } from "fok-js";

console.log(getBirthdayByIDcard('123456789012345678'));
//身份证号出生日期不合规
console.log(getBirthdayByIDcard('510824197101103465'));
//身份证号格式错误
console.log(getBirthdayByIDcard('510824197101107365'));
//1971-01-10





############### 源码 #################
/**
 *
 * @desc 根据身份证号返回出生日期。
 * @param  {val} string 身份证号。
 * @return string 出生日期
 */
function getBirthdayByIDcard(identityCard) {
	let len = (identityCard + "").length;
	let result = isIdCard(identityCard);
	if(result === true) {
		// 提取出生日期
		let birthday = identityCard.substring(6, 14);
		let year = birthday.substring(0, 4);
		let month = birthday.substring(4, 6);
		let day = birthday.substring(6, 8);
		return year + '-' + month + '-' + day;
	}
	else {
		return result;
	}
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_getgenderbyidcard_根据身份证号返回性别">getGenderByIDcard 根据身份证号返回性别</h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getGenderByIDcard } from "fok-js";

console.log(getGenderByIDcard('123456789012345678'));
//身份证号出生日期不合规
console.log(getGenderByIDcard('510824197101103465'));
//身份证号格式错误
console.log(getGenderByIDcard('510824197101107365'));
//女





############### 源码 #################
/**
 *
 * @desc 根据身份证号返回性别。
 * @param  {val} string 身份证号。
 * @return string 性别
 */
function getGenderByIDcard(identityCard) {
	let len = (identityCard + "").length;
	let result = isIdCard(identityCard);
	if(result === true) {
		// 提取性别
		let genderCode = parseInt(identityCard.charAt(16));
		let gender = genderCode % 2 === 0 ? "女" : "男";
		return gender;
	}
	else {
		return result;
	}
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_gettypename_获取变量数据类型名称">getTypeName 获取变量数据类型名称</h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { getTypeName } from "fok-js";

console.log(getTypeName('123456789012345678'));
// string





############### 源码 #################
/**
 * 获取变量数据类型名称
 * @param {*} variable 变量
 * @returns 类型名称
 */
function getTypeName(variable) {
  const typeString = Object.prototype.toString.call(variable);
  const matchResult = typeString.match(/\[object (\w+)\]/);
  if (matchResult &amp;&amp; matchResult.length &gt; 1) {
    return matchResult[1].toLowerCase();
  } else {
    throw new Error('Invalid input');
  }
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_isarray_是否是数组">isArray 是否是数组</h4>
<div class="paragraph">
<p>检查 value 是否是 Array 类对象。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { isArray } from "fok-js";
console.log(isArray([1, 2, 3]));
//true
console.log(isArray(document.body.children));
//false
console.log(isArray('abc'));
//false





############### 源码 #################
/**
 *
 * @desc 检查 value 是否是 Array 类对象。
 * @param {value(*)}  要检查的值
 * @return boolean 如果value是一个数组返回 true，否则返回 false
 */
function isArray(value) {
    return value != null &amp;&amp; getTypeName(value) === 'array';
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_isboolean_是否是布尔值">isBoolean 是否是布尔值</h4>
<div class="paragraph">
<p>检查 value 是否是原始 boolean 类型或者对象。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { isBoolean } from "fok-js";

console.log(isBoolean(false));
//true
console.log(isBoolean(null));
//false</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_isfunction_是否是函数">isFunction 是否是函数</h4>
<div class="paragraph">
<p>检查 value 是否是 Function 对象。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { isFunction } from "fok-js";

console.log(isFunction(() =&gt; {}));
//true
console.log(isFunction(/abc/));
//false





############### 源码 #################
/**
 * @desc 检查 value 是否是 Function 对象。
 * @param {value(*)}  要检查的值
 * @return boolean 如果 value 是一个函数，那么返回 true，否则返回 false
 */
function isFunction(value) {
	return typeof value === 'function';
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_isnull_是否是null">isNull 是否是null</h4>
<div class="paragraph">
<p>检查 valuealue 是否是 null。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { isNull } from "fok-js";
console.log(isNull(null));
//true
console.log(isNull(void 0));
//false





############### 源码 #################
/**
 * @desc 检查 valuealue 是否是 null。
 * @param {value(*)}  要检查的值
 * @return boolean 如果 value 为null，那么返回 true，否则返回 false
 */

function isNull(value) {
	return value === null;
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_isobject_是否是对象">isObject 是否是对象</h4>
<div class="paragraph">
<p>检查 value 是否为 Object 的language type。 (例如： arrays, functions, objects, regexes,new Number(0), 以及 new String(''))。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { isObject } from "fok-js";

console.log(isObject({}));
//true
console.log(isObject([1, 2, 3]));
//true
console.log(isObject(null));
//false





############### 源码 #################
/**
 * @desc 检查 value 是否为 Object 的language type。 (例如： arrays, functions, objects, regexes,new Number(0), 以及 new String(''))
 * @param {value(*)}  要检查的值
 * @return boolean 如果 value 为一个对象，那么返回 true，否则返回 false
 */

function isObject(value) {
	return value != null &amp;&amp; getTypeName(value) === 'object';
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_isstring_是否是字符串">isString 是否是字符串</h4>
<div class="paragraph">
<p>检查 value 是否是原始字符串String或者对象。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { isString } from "fok-js";

console.log(isString('abc'));
//true
console.log(isString(1));
//false






############### 源码 #################
/**
 * @desc 检查 value 是否是原始字符串String或者对象。
 * @param {value(*)}  要检查的值
 * @return boolean 如果 value 为一个字符串，那么返回 true，否则返回 false
 */
function isString(value) {
	const type = typeof value;
	return (
		type === 'string' ||
		(type === 'object' &amp;&amp;
			value != null &amp;&amp;
			!Array.isArray(value) &amp;&amp;
			getTag(value) === '[object String]')
	);
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_returnlistname_返回下拉列表名称">returnListName 返回下拉列表名称</h4>
<div class="paragraph">
<p>返回下拉列表名称，名称可以是label或者name。</p>
</div>
<div class="paragraph">
<p>参数有二：第一个参数是下拉列表数组，第二个是需要查询的值。</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { returnListName } from "fok-js";

const classesList = [ //班次
  {
    label: '请选择',
    value: ''
  },
  {
    label: '上午',
    value: 'morning'
  },
  {
    label: '下午',
    value: 'afternoon'
  },
  {
    label: '夜班',
    value: 'nightShift'
  },
  {
    label: '全天',
    value: 'allDay'
  }
];
console.log(returnListName(classesList, 'afternoon'));
//下午





############### 源码 #################
/**
 * @desc 返回下拉列表对应值的名称。
 * @param  {list} array 下拉列表数组。
 * @param  {val} string | number  需要返回名称的值。
 * @return string 对应值的中文名称
 */
function returnListName(list, val) {
	let item = list.find((items) =&gt; {
		return items.value === val
	})
	if (item) {
		return item.label || item.name;
	} else {
		console.log('无匹配内容');
		return ''
	}
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_url">url</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_parsequerystring_url参数转对象">parseQueryString url参数转对象</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { parseQueryString } from 'fok-utils';

console.log(parseQueryString('www.baidu.com?aaa=123&amp;bbb=sfd'));
// {aaa: "123", bbb: "sfd"}





############### 源码 #################
/**
 * @desc   url参数转对象
 * @param  {String} url  default: window.location.href
 * @return {any}
 */
function parseQueryString(url) {
    url = !url ? window.location.href : url;
    if(url.indexOf('?') === -1) {
        return {};
    }
    let search = url[0] === '?' ? url.substr(1) : url.substring(url.lastIndexOf('?') + 1);
    if (search === '') {
        return {};
    }
    search = search.split('&amp;');
    let query = {};
    for (let i = 0; i &lt; search.length; i++) {
        let pair = search[i].split('=');
        query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
    }
    return query;
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_stringfyquerystring_对象序列化">stringfyQueryString 对象序列化</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">import { stringfyQueryString } from 'fok-utils';

let obj = {aaa: "123", bbb: "sfd"};
console.log(stringfyQueryString(obj));
// aaa=123&amp;bbb=sfd





############### 源码 #################
/**
 * @desc   对象序列化
 * @param  {any} obj
 * @return {String}
 */
function stringfyQueryString(obj) {
    if (!obj) return '';
    let pairs = [];

    for (let key in obj) {
        let value = obj[key];

        if (value instanceof Array) {
            for (let i = 0; i &lt; value.length; ++i) {
                pairs.push(encodeURIComponent(key + '[' + i + ']') + '=' + encodeURIComponent(value[i]));
            }
            continue;
        }

        pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));
    }

    return pairs.join('&amp;');
}</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2024-10-26 16:05:34 +0800
</div>
</div>
</body>
</html>